[3397] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : MyPolls.2 |
---|
| 4 | Author : Grum |
---|
| 5 | email : grum@piwigo.org |
---|
| 6 | website : http://photos.grum.dnsalias.com |
---|
| 7 | |
---|
| 8 | << May the Little SpaceFrog be with you ! >> |
---|
| 9 | ------------------------------------------------------------------------------ |
---|
| 10 | See main.inc.php for release information |
---|
| 11 | |
---|
| 12 | MyPolls_AIP : classe to manage plugin admin pages |
---|
| 13 | |
---|
| 14 | --------------------------------------------------------------------------- */ |
---|
| 15 | |
---|
| 16 | include_once('mypolls_root.class.inc.php'); |
---|
| 17 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/translate.class.inc.php'); |
---|
| 18 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/tables.class.inc.php'); |
---|
| 19 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/genericjs.class.inc.php'); |
---|
| 20 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 21 | |
---|
| 22 | class MyPolls_AIP extends MyPolls_root |
---|
| 23 | { |
---|
| 24 | protected $google_translate; |
---|
| 25 | protected $tabsheet; |
---|
| 26 | |
---|
| 27 | public function MyPolls_AIP($prefixeTable, $filelocation) |
---|
| 28 | { |
---|
| 29 | parent::__construct($prefixeTable, $filelocation); |
---|
| 30 | $this->load_config(); |
---|
| 31 | $this->init_events(); |
---|
| 32 | |
---|
| 33 | $this->tabsheet = new tabsheet(); |
---|
| 34 | $this->tabsheet->add('polls', |
---|
| 35 | l10n('mypolls_polls'), |
---|
| 36 | $this->page_link."&f_tabsheet=polls"); |
---|
| 37 | $this->tabsheet->add('config', |
---|
| 38 | l10n('mypolls_config'), |
---|
| 39 | $this->page_link."&f_tabsheet=config"); |
---|
| 40 | |
---|
| 41 | // don't create this object inside root classe otherwise header is modified |
---|
| 42 | // everywhere in admin pages |
---|
| 43 | $this->ajax = new Ajax(); |
---|
| 44 | |
---|
| 45 | // don't create the google_translate object everytime, otherwise google's js |
---|
| 46 | // code is always included in the header even if translation functionalities |
---|
| 47 | // aren't needed |
---|
| 48 | // translation is needed only if we are in a ajax request |
---|
| 49 | if((isset($_POST['fmypolls_gomodify_translation'])||isset($_POST['fmypolls_goadd_translation']))) |
---|
| 50 | { |
---|
| 51 | $this->google_translate = new translate(); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | initialize events call for the plugin |
---|
| 58 | */ |
---|
| 59 | public function init_events() |
---|
| 60 | { |
---|
| 61 | parent::init_events(); |
---|
| 62 | add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS')); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | display administration page |
---|
| 67 | */ |
---|
| 68 | public function manage() |
---|
| 69 | { |
---|
| 70 | global $template; |
---|
| 71 | |
---|
| 72 | $this->return_ajax_content(); |
---|
| 73 | |
---|
| 74 | $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/mypolls_admin.tpl"); |
---|
| 75 | |
---|
| 76 | if(!isset($_REQUEST['f_tabsheet'])) |
---|
| 77 | { |
---|
| 78 | $_REQUEST['f_tabsheet']='polls'; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | switch($_REQUEST['f_tabsheet']) |
---|
| 82 | { |
---|
| 83 | case 'polls': |
---|
| 84 | $this->display_polls_page(); |
---|
| 85 | break; |
---|
| 86 | case 'config': |
---|
| 87 | $this->display_config_page(); |
---|
| 88 | break; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | $this->tabsheet->select($_REQUEST['f_tabsheet']); |
---|
| 92 | $this->tabsheet->assign(); |
---|
| 93 | $selected_tab=$this->tabsheet->get_selected(); |
---|
| 94 | $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]"); |
---|
| 95 | |
---|
| 96 | $template_plugin["MYPOLLS_VERSION"] = "<i>".$this->plugin_name."</i> ".l10n('mypolls_version').MYPOLLS_VERSION; |
---|
| 97 | $template_plugin["MYPOLLS_PAGE"] = $_REQUEST['f_tabsheet']; |
---|
| 98 | |
---|
| 99 | $template->assign('plugin', $template_plugin); |
---|
| 100 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | /* |
---|
| 105 | return ajax content |
---|
| 106 | */ |
---|
| 107 | protected function return_ajax_content() |
---|
| 108 | { |
---|
| 109 | global $ajax, $template; |
---|
| 110 | |
---|
| 111 | if(isset($_REQUEST['ajaxfct'])) |
---|
| 112 | { |
---|
| 113 | //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']); |
---|
| 114 | $result="<p class='errors'>An error has occured</p>"; |
---|
| 115 | switch($_REQUEST['ajaxfct']) |
---|
| 116 | { |
---|
| 117 | case 'poll_detail_list': |
---|
| 118 | $result=$this->ajax_poll_detail_list($_REQUEST['poll_id']); |
---|
| 119 | break; |
---|
| 120 | case 'poll_user_list': |
---|
| 121 | $result=$this->ajax_poll_user_list($_REQUEST['poll_id']); |
---|
| 122 | break; |
---|
| 123 | case 'poll_comment_list': |
---|
| 124 | $result=$this->ajax_poll_comment_list($_REQUEST['poll_id']); |
---|
| 125 | break; |
---|
| 126 | case 'poll_delete_comment': |
---|
| 127 | $result=$this->ajax_poll_delete_comment($_REQUEST['poll_id']); |
---|
| 128 | break; |
---|
| 129 | } |
---|
| 130 | //$template-> |
---|
| 131 | $this->ajax->return_result($result); |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | manage display of config page & save config |
---|
| 138 | */ |
---|
| 139 | protected function display_config_page() |
---|
| 140 | { |
---|
| 141 | $languages=get_languages(); |
---|
| 142 | if(!$this->adviser_abort()) |
---|
| 143 | { |
---|
| 144 | if(isset($_POST['submit_save_config'])) |
---|
| 145 | { |
---|
| 146 | foreach($this->my_config as $key => $val) |
---|
| 147 | { |
---|
| 148 | if(is_array($val)) |
---|
| 149 | { |
---|
| 150 | foreach($languages as $key2 => $val2) |
---|
| 151 | { |
---|
| 152 | if(isset($_REQUEST[str2url('f_'.$key.'_'.$key2)])) |
---|
| 153 | { |
---|
| 154 | $this->my_config[$key][$key2] = htmlspecialchars(stripslashes($_REQUEST[str2url('f_'.$key.'_'.$key2)]), ENT_QUOTES); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | if(isset($_REQUEST['f_'.$key])) |
---|
| 161 | { |
---|
| 162 | $this->my_config[$key] = $_REQUEST['f_'.$key]; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | } |
---|
| 167 | $this->display_result(l10n('mypolls_save_config'), $this->save_config()); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | $this->display_config(); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | /* |
---|
| 176 | manage display of polls pages actions : |
---|
| 177 | - list |
---|
| 178 | - create |
---|
| 179 | - view |
---|
| 180 | - modify/delete |
---|
| 181 | */ |
---|
| 182 | protected function display_polls_page() |
---|
| 183 | { |
---|
| 184 | //default action if not specified into URL's page |
---|
| 185 | if(!isset($_REQUEST['action'])) |
---|
| 186 | { |
---|
| 187 | $_REQUEST['action']='list'; |
---|
| 188 | } |
---|
| 189 | if(!isset($_REQUEST['fmypolls_att_id'])) |
---|
| 190 | { |
---|
| 191 | $_REQUEST['fmypolls_att_id']=''; |
---|
| 192 | } |
---|
| 193 | if(($_REQUEST['action']!='create') and ($_REQUEST['fmypolls_att_id']=='') ) |
---|
| 194 | { |
---|
| 195 | $_REQUEST['action']='list'; |
---|
| 196 | } |
---|
| 197 | if(!isset($_REQUEST['mypolls_step'])) |
---|
| 198 | { |
---|
| 199 | $_REQUEST['mypolls_step']=0; |
---|
| 200 | } |
---|
| 201 | if(!isset($_REQUEST['mypolls_lang'])) |
---|
| 202 | { |
---|
| 203 | $_REQUEST['mypolls_lang']=""; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | //$this->debug('action:'.$_REQUEST['action']); |
---|
| 207 | //$this->debug('fmypolls_att_id:'.$_REQUEST['fmypolls_att_id']); |
---|
| 208 | //$this->debug('step:'.$_REQUEST['mypolls_step']); |
---|
| 209 | switch($_REQUEST['action']) |
---|
| 210 | { |
---|
| 211 | case 'list': |
---|
| 212 | $this->display_list(); |
---|
| 213 | break; |
---|
| 214 | case 'create': |
---|
| 215 | if(isset($_POST['fmypolls_create_new_poll'])) |
---|
| 216 | { |
---|
| 217 | if($this->adviser_abort()) |
---|
| 218 | { |
---|
| 219 | $this->display_list(); |
---|
| 220 | break; |
---|
| 221 | } |
---|
| 222 | $poll_id=$this->do_create_poll(0); |
---|
| 223 | $this->display_result(l10n('mypolls_msg_create_new_poll'), $poll_id); |
---|
| 224 | $this->display_cm_page0($this->init_poll_array($poll_id), 'modify', $poll_id); |
---|
| 225 | } |
---|
| 226 | else |
---|
| 227 | { |
---|
| 228 | $this->display_cm_page0(); |
---|
| 229 | } |
---|
| 230 | break; |
---|
| 231 | case 'view': |
---|
| 232 | $this->display_view($_REQUEST['fmypolls_att_id'], $_REQUEST['mypolls_lang']); |
---|
| 233 | break; |
---|
| 234 | case 'modify': |
---|
| 235 | case 'adding': |
---|
| 236 | if(isset($_POST['fmypolls_modify_poll'])) |
---|
| 237 | { |
---|
| 238 | if($this->adviser_abort()) |
---|
| 239 | { |
---|
| 240 | $this->display_list(); |
---|
| 241 | break; |
---|
| 242 | } |
---|
| 243 | //modify a poll |
---|
| 244 | $result=$this->do_modify_poll(0, $_REQUEST['fmypolls_att_id']); |
---|
| 245 | $this->display_result(l10n('mypolls_msg_modify_poll'), $result); |
---|
| 246 | //go back to poll's main page in 'modify' mode |
---|
| 247 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 248 | 'modify', |
---|
| 249 | $_REQUEST['fmypolls_att_id']); |
---|
| 250 | } |
---|
| 251 | elseif(isset($_POST['fmypolls_delete_poll'])) |
---|
| 252 | { |
---|
| 253 | if($this->adviser_abort()) |
---|
| 254 | { |
---|
| 255 | $this->display_list(); |
---|
| 256 | break; |
---|
| 257 | } |
---|
| 258 | //delete a poll |
---|
| 259 | $result=$this->do_delete_poll($_REQUEST['fmypolls_att_id']); |
---|
| 260 | $this->display_result(l10n('mypolls_msg_delete_poll'), $result); |
---|
| 261 | //go back to list |
---|
| 262 | $this->display_list(); |
---|
| 263 | } |
---|
| 264 | elseif(isset($_POST['fmypolls_add_question'])) |
---|
| 265 | { |
---|
| 266 | if($this->adviser_abort()) |
---|
| 267 | { |
---|
| 268 | $this->display_list(); |
---|
| 269 | break; |
---|
| 270 | } |
---|
| 271 | //add a question on poll |
---|
| 272 | $result=$this->do_create_poll($_REQUEST['mypolls_step']); |
---|
| 273 | $this->display_result(l10n('mypolls_msg_add_question'), $result); |
---|
| 274 | //go back to poll's main page in 'modify' mode |
---|
| 275 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 276 | 'modify', |
---|
| 277 | $_REQUEST['fmypolls_att_id']); |
---|
| 278 | } |
---|
| 279 | elseif(isset($_POST['fmypolls_modify_question'])) |
---|
| 280 | { |
---|
| 281 | if($this->adviser_abort()) |
---|
| 282 | { |
---|
| 283 | $this->display_list(); |
---|
| 284 | break; |
---|
| 285 | } |
---|
| 286 | //modify a poll's question |
---|
| 287 | $result=$this->do_modify_poll($_REQUEST['mypolls_step'], |
---|
| 288 | $_REQUEST['fmypolls_att_id']); |
---|
| 289 | $this->display_result(l10n('mypolls_msg_modify_question'), $result); |
---|
| 290 | //go back to poll's main page in 'modify' mode |
---|
| 291 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 292 | 'modify', |
---|
| 293 | $_REQUEST['fmypolls_att_id']); |
---|
| 294 | } |
---|
| 295 | elseif(isset($_POST['fmypolls_delete_question'])) |
---|
| 296 | { |
---|
| 297 | if($this->adviser_abort()) |
---|
| 298 | { |
---|
| 299 | $this->display_list(); |
---|
| 300 | break; |
---|
| 301 | } |
---|
| 302 | //delete a poll's question |
---|
| 303 | $result=$this->do_delete_question($_REQUEST['mypolls_step'], $_REQUEST['fmypolls_att_id']); |
---|
| 304 | $this->display_result(l10n('mypolls_msg_delete_question'), $result); |
---|
| 305 | //go back to poll's main page in 'modify' mode |
---|
| 306 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 307 | 'modify', |
---|
| 308 | $_REQUEST['fmypolls_att_id']); |
---|
| 309 | } |
---|
| 310 | elseif(isset($_POST['fmypolls_add_translation'])) |
---|
| 311 | { |
---|
| 312 | if($this->adviser_abort()) |
---|
| 313 | { |
---|
| 314 | $this->display_list(); |
---|
| 315 | break; |
---|
| 316 | } |
---|
| 317 | //add a translation on poll |
---|
| 318 | $result=$this->do_translate_poll($_REQUEST['fmypolls_att_id'], 'adding'); |
---|
| 319 | $this->display_result(l10n('mypolls_msg_add_translation'), $result); |
---|
| 320 | //go back to poll's main page in 'modify' mode |
---|
| 321 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 322 | 'modify', |
---|
| 323 | $_REQUEST['fmypolls_att_id']); |
---|
| 324 | } |
---|
| 325 | elseif(isset($_POST['fmypolls_modify_translation'])) |
---|
| 326 | { |
---|
| 327 | if($this->adviser_abort()) |
---|
| 328 | { |
---|
| 329 | $this->display_list(); |
---|
| 330 | break; |
---|
| 331 | } |
---|
| 332 | //delete a poll's question |
---|
| 333 | $result=$this->do_translate_poll($_REQUEST['fmypolls_att_id'], 'modify'); |
---|
| 334 | $this->display_result(l10n('mypolls_msg_modify_translation'), $result); |
---|
| 335 | //go back to poll's main page in 'modify' mode |
---|
| 336 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 337 | 'modify', |
---|
| 338 | $_REQUEST['fmypolls_att_id']); |
---|
| 339 | } |
---|
| 340 | elseif(isset($_POST['fmypolls_delete_translation'])) |
---|
| 341 | { |
---|
| 342 | if($this->adviser_abort()) |
---|
| 343 | { |
---|
| 344 | $this->display_list(); |
---|
| 345 | break; |
---|
| 346 | } |
---|
| 347 | //delete a poll's question |
---|
| 348 | $result=$this->do_delete_poll_translation($_REQUEST['fmypolls_att_id'], $_REQUEST['fmypolls_trans_to']); |
---|
| 349 | $this->display_result(l10n('mypolls_msg_delete_translation'), $result); |
---|
| 350 | //go back to poll's main page in 'modify' mode |
---|
| 351 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 352 | 'modify', |
---|
| 353 | $_REQUEST['fmypolls_att_id']); |
---|
| 354 | } |
---|
| 355 | elseif(isset($_POST['fmypolls_gomodify_question'])) |
---|
| 356 | { |
---|
| 357 | $ansid=explode(".", $_REQUEST['mypolls_step']); |
---|
| 358 | //go to poll's question page in 'modify' mode |
---|
| 359 | $this->display_cm_pagen($_REQUEST['mypolls_step'], |
---|
| 360 | $_REQUEST['fmypolls_att_id'], |
---|
| 361 | $this->init_poll_question_array($_REQUEST['fmypolls_att_id'], $ansid[0]), |
---|
| 362 | 'modify'); |
---|
| 363 | } |
---|
| 364 | elseif(isset($_POST['fmypolls_goadd_question'])) |
---|
| 365 | { |
---|
| 366 | //go to poll's question page in 'adding' mode |
---|
| 367 | $this->display_cm_pagen($_REQUEST['mypolls_step'], |
---|
| 368 | $_REQUEST['fmypolls_att_id'], array(), 'adding'); |
---|
| 369 | } |
---|
| 370 | elseif(isset($_POST['fmypolls_gomodify_translation'])) |
---|
| 371 | { |
---|
| 372 | //go to poll's translation page in 'modify' mode |
---|
| 373 | $this->display_translation_page($_REQUEST['fmypolls_att_id'], $_REQUEST['fmypolls_translation_id'],'modify'); |
---|
| 374 | } |
---|
| 375 | elseif(isset($_POST['fmypolls_goadd_translation'])) |
---|
| 376 | { |
---|
| 377 | //go to poll's translation page in 'modify' mode |
---|
| 378 | $this->display_translation_page($_REQUEST['fmypolls_att_id'], '', 'adding'); |
---|
| 379 | } |
---|
| 380 | else |
---|
| 381 | { |
---|
| 382 | //go to poll's main page in 'modify' mode |
---|
| 383 | $this->display_cm_page0($this->init_poll_array($_REQUEST['fmypolls_att_id']), |
---|
| 384 | 'modify', |
---|
| 385 | $_REQUEST['fmypolls_att_id']); |
---|
| 386 | } |
---|
| 387 | break; |
---|
| 388 | } |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | /* |
---|
| 392 | display list page of polls and allow to : |
---|
| 393 | - view a poll |
---|
| 394 | - modify a poll |
---|
| 395 | - create a new poll |
---|
| 396 | */ |
---|
| 397 | protected function display_list() |
---|
| 398 | { |
---|
| 399 | global $template, $user; |
---|
| 400 | $template->set_filename('body_page', |
---|
| 401 | dirname($this->filelocation).'/admin/plugin_admin_list.tpl'); |
---|
| 402 | |
---|
| 403 | $polls_list=$this->get_polls_list(1,true); |
---|
| 404 | if(count($polls_list)>1) |
---|
| 405 | { $nb='n'; } else { $nb=count($polls_list); } |
---|
| 406 | |
---|
| 407 | $template_datas=array(); |
---|
| 408 | $template_datarows=array(); |
---|
| 409 | |
---|
| 410 | for($i=0;$i<count($polls_list);$i++) |
---|
| 411 | { |
---|
| 412 | if($polls_list[$i]['total_votes']>0) |
---|
| 413 | { |
---|
| 414 | $last_vote = $polls_list[$i]['last_vote']; |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | $last_vote = ""; |
---|
| 419 | } |
---|
| 420 | $template_datarows[]=array( |
---|
| 421 | 'ID' => $polls_list[$i]['id'], |
---|
| 422 | 'DATE' => substr($polls_list[$i]['date'],0,10), |
---|
| 423 | 'TITLE' => $polls_list[$i]['title'], |
---|
| 424 | 'NBQUESTIONS' => $polls_list[$i]['nb_questions'], |
---|
| 425 | 'VISIBLE' => l10n('mypolls_yesno_'.$polls_list[$i]['visible']), |
---|
| 426 | 'ENABLED' => l10n('mypolls_yesno_'.$polls_list[$i]['enabled']), |
---|
| 427 | 'TOTAL' => $polls_list[$i]['total_votes'], |
---|
| 428 | 'LAST_VOTE' => $last_vote, |
---|
| 429 | 'LNK_VIEW' => $this->page_link. |
---|
| 430 | '&f_tabsheet=polls&action=view&fmypolls_att_id='. |
---|
| 431 | $polls_list[$i]['id'], |
---|
| 432 | 'LNK_MODIFY' => $this->page_link. |
---|
| 433 | '&f_tabsheet=polls&action=modify&fmypolls_att_id='. |
---|
| 434 | $polls_list[$i]['id'] |
---|
| 435 | ); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | $template_datas=array( |
---|
| 439 | "MYPOLLS_TITLE" => l10n('mypolls_title_list'), |
---|
| 440 | "MYPOLLS_NB_POLLS" => sprintf(l10n('mypolls_number_of_polls'.$nb), count($polls_list)), |
---|
| 441 | "LNK_CREATE" => $this->page_link.'&f_tabsheet=polls&action=create', |
---|
| 442 | "MYPOLLS_AJAX_URL_POLL_DETAIL" => $this->page_link.'&ajaxfct=poll_detail_list&poll_id=', |
---|
| 443 | "MYPOLLS_CHARSET" => substr($user['language'],6) |
---|
| 444 | ); |
---|
| 445 | |
---|
| 446 | $template->assign("datas", $template_datas); |
---|
| 447 | $template->assign("mypolls_nb_polls_rows", $template_datarows); |
---|
| 448 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 449 | } |
---|
| 450 | |
---|
| 451 | |
---|
| 452 | /* |
---|
| 453 | display first page to create/modify a poll (poll's attributes) |
---|
| 454 | page can be acceded : |
---|
| 455 | - when poll is created (no default_values) |
---|
| 456 | - when poll is created but with an error (default_values are form's values) |
---|
| 457 | - when poll is modified (default_values are database values) |
---|
| 458 | - when poll is modified but with an error (default_values are form's values) |
---|
| 459 | |
---|
| 460 | $access_type = "create", "modify" |
---|
| 461 | */ |
---|
| 462 | protected function display_cm_page0($default_values=array(), $access_type = "create", $poll_id=0) |
---|
| 463 | { |
---|
| 464 | global $template, $user, $page; |
---|
| 465 | |
---|
| 466 | $template->set_filename('body_page', |
---|
| 467 | dirname($this->filelocation).'/admin/plugin_admin_create.tpl'); |
---|
| 468 | |
---|
| 469 | $template_datas=array(); |
---|
| 470 | |
---|
| 471 | if($access_type=='create') |
---|
| 472 | { |
---|
| 473 | $template_datas['MYPOLLS_ICN_HIDDEN']='visibility:hidden;'; |
---|
| 474 | $template_datas['MYPOLLS_NEXT_STEP']='0.1'; |
---|
| 475 | $template_datas['MYPOLLS_ENABLED']=' disabled'; |
---|
| 476 | } |
---|
| 477 | else |
---|
| 478 | { |
---|
| 479 | $template_datas['MYPOLLS_LANG_DISABLED']='disabled'; |
---|
| 480 | $template_datas['MYPOLLS_LNK_VIEW'] = $this->page_link.'&f_tabsheet=polls&action=view&fmypolls_att_id='.$poll_id; |
---|
| 481 | $template_datas['MYPOLLS_NEXT_STEP'] = ($default_values['counter_questions']+1).".".($default_values['nb_questions']+1); |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | //check if number of questions/answers is the same for each language |
---|
| 485 | $sql="SELECT count(id_answer), lang |
---|
| 486 | FROM ".$this->tables['polls_answers_lang']." |
---|
| 487 | WHERE id_poll = '".$poll_id."' |
---|
| 488 | GROUP BY lang"; |
---|
| 489 | $result=pwg_query($sql); |
---|
| 490 | if($result) |
---|
| 491 | { |
---|
| 492 | $nb=-1; |
---|
| 493 | while($row=mysql_fetch_row($result)) |
---|
| 494 | { |
---|
| 495 | if($nb<0) |
---|
| 496 | { |
---|
| 497 | $nb=$row[0]; |
---|
| 498 | } |
---|
| 499 | elseif($nb!=$row[0]) |
---|
| 500 | { |
---|
| 501 | $nb=-2; |
---|
| 502 | array_push($page['errors'], l10n('mypolls_error_on_tranlsation_number')); |
---|
| 503 | break; |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | if(($default_values['nb_questions']<1)||($nb==-2)) |
---|
| 509 | { |
---|
| 510 | $template_datas['MYPOLLS_ENABLED']= ' disabled'; |
---|
| 511 | $default_values['enabled']='n'; |
---|
| 512 | $this->deactivate_poll($poll_id); |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | $template_datas['MYPOLLS_ACTION']= $access_type; |
---|
| 516 | |
---|
| 517 | //no default value, so initialization |
---|
| 518 | if(count($default_values)==0) |
---|
| 519 | { |
---|
| 520 | $allowed_users=""; |
---|
| 521 | if($this->my_config['mypolls_allowed_users_default_guest']=='y') |
---|
| 522 | { $allowed_users.="guest/"; } |
---|
| 523 | if($this->my_config['mypolls_allowed_users_default_generic']=='y') |
---|
| 524 | { $allowed_users.="generic/"; } |
---|
| 525 | if($this->my_config['mypolls_allowed_users_default_normal']=='y') |
---|
| 526 | { $allowed_users.="normal/"; } |
---|
| 527 | |
---|
| 528 | $default_values=array( |
---|
| 529 | 'default_lang' => $user['language'], |
---|
| 530 | 'title' => '', |
---|
| 531 | 'description' => '', |
---|
| 532 | 'after_vote_text' => '', |
---|
| 533 | 'allowed_users' => $allowed_users, |
---|
| 534 | 'allowed_groups' => $this->my_config['mypolls_allowed_groups_default'], |
---|
| 535 | 'enabled' => 'n', |
---|
| 536 | 'visible' => $this->my_config['mypolls_visible_default'], |
---|
| 537 | 'allow_comment' => $this->my_config['mypolls_allow_comment_default'], |
---|
| 538 | 'show_comments' => $this->my_config['mypolls_show_user_comment_default'], |
---|
| 539 | 'display_type' => $this->my_config['mypolls_display_type_default'], |
---|
| 540 | 'color_bars' => $this->my_config['mypolls_color_bars'], |
---|
| 541 | 'public_results' => $this->my_config['mypolls_public_results'] |
---|
| 542 | ); |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | |
---|
| 546 | $template_datas['MYPOLLS_ATT_TITLE'] = $default_values['title']; |
---|
| 547 | $template_datas['MYPOLLS_ATT_DESCRIPTION'] = $default_values['description']; |
---|
| 548 | $template_datas['MYPOLLS_ATT_AFTER_VOTE_TEXT'] = $default_values['after_vote_text']; |
---|
| 549 | |
---|
| 550 | //users and groups access management |
---|
| 551 | $users = new users($default_values['allowed_users']); |
---|
| 552 | $template_datas['GENERIC_USERS_ACCESS'] = $users->html_form('fmypolls_att_allowed_users_'); |
---|
| 553 | |
---|
| 554 | $groups = new groups($default_values['allowed_groups']); |
---|
| 555 | $template_datas['GENERIC_GROUPS_ACCESS'] = $groups->html_form('fmypolls_att_allowed_groups_'); |
---|
| 556 | |
---|
| 557 | |
---|
| 558 | //poll's main language selection |
---|
| 559 | $template_language_list_values=array(); |
---|
| 560 | $template_language_list_labels=array(); |
---|
| 561 | $template_language_selected=$default_values['default_lang']; |
---|
| 562 | $languages=get_languages(); |
---|
| 563 | foreach($languages as $key => $val) |
---|
| 564 | { |
---|
| 565 | $template_language_list_values[]=$key; |
---|
| 566 | $template_language_list_labels[]=$val; |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | //poll's type of display (one page for all question / a page per question) |
---|
| 570 | $template_display_list_values=array(); |
---|
| 571 | $template_display_list_labels=array(); |
---|
| 572 | $template_display_selected=$default_values['display_type']; |
---|
| 573 | for($i=0;$i<count($this->display_types);$i++) |
---|
| 574 | { |
---|
| 575 | $template_display_list_values[]=$this->display_types[$i]; |
---|
| 576 | $template_display_list_labels[]=l10n('mypolls_display_'.$this->display_types[$i]); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | if($default_values['enabled']=='y') |
---|
| 580 | { $template_datas['MYPOLLS_ATT_ENABLED_YES'] = 'selected'; } |
---|
| 581 | else |
---|
| 582 | { $template_datas['MYPOLLS_ATT_ENABLED_NO'] = 'selected'; } |
---|
| 583 | |
---|
| 584 | if($default_values['visible']=='y') |
---|
| 585 | { $template_datas['MYPOLLS_ATT_VISIBLE_YES'] = 'selected'; } |
---|
| 586 | else |
---|
| 587 | { $template_datas['MYPOLLS_ATT_VISIBLE_NO'] = 'selected'; } |
---|
| 588 | |
---|
| 589 | if($default_values['allow_comment']=='y') |
---|
| 590 | { $template_datas['MYPOLLS_ATT_ALLOW_COMMENT_YES'] = 'selected'; } |
---|
| 591 | else |
---|
| 592 | { $template_datas['MYPOLLS_ATT_ALLOW_COMMENT_NO'] = 'selected'; } |
---|
| 593 | |
---|
| 594 | if($default_values['show_comments']=='y') |
---|
| 595 | { $template_datas['MYPOLLS_ATT_SHOW_USER_COMMENT_YES'] = 'selected'; } |
---|
| 596 | else |
---|
| 597 | { $template_datas['MYPOLLS_ATT_SHOW_USER_COMMENT_NO'] = 'selected'; } |
---|
| 598 | |
---|
| 599 | if($default_values['public_results']=='y') |
---|
| 600 | { $template_datas['MYPOLLS_ATT_PUBLIC_RESULTS_YES'] = 'selected'; } |
---|
| 601 | else |
---|
| 602 | { $template_datas['MYPOLLS_ATT_PUBLIC_RESULTS_NO'] = 'selected'; } |
---|
| 603 | |
---|
| 604 | $template_datas['fmypolls_att_color_bars'] = $default_values['color_bars']; |
---|
| 605 | |
---|
| 606 | |
---|
| 607 | if($access_type=='create') |
---|
| 608 | { |
---|
| 609 | $template_datas['mypolls_en_creation']='yes'; |
---|
| 610 | } |
---|
| 611 | else |
---|
| 612 | { |
---|
| 613 | $nbquestions = $default_values['nb_questions']." "; |
---|
| 614 | $poll_languages=$this->get_poll_languages($poll_id); |
---|
| 615 | |
---|
| 616 | if($default_values['nb_questions']>1) |
---|
| 617 | { $nbquestions.=l10n('mypolls_cm_questions'); } |
---|
| 618 | else |
---|
| 619 | { $nbquestions.=l10n('mypolls_cm_question'); } |
---|
| 620 | //modify poll, display specifics block for actions |
---|
| 621 | $template_datas['mypolls_en_modification']='yes'; |
---|
| 622 | |
---|
| 623 | $template_datas['ID'] = $poll_id; |
---|
| 624 | $template_datas['NBQUESTIONS'] = $nbquestions; |
---|
| 625 | $template_datas['DISABLE_ADD_TRANS'] = (count($poll_languages)==count($languages))?' disabled':''; |
---|
| 626 | |
---|
| 627 | // block : questions |
---|
| 628 | $template_questions_list_values=array(); |
---|
| 629 | $template_questions_list_labels=array(); |
---|
| 630 | $num=1; |
---|
| 631 | $questions=$this->get_poll_questions($poll_id); |
---|
| 632 | foreach($questions as $val) |
---|
| 633 | { |
---|
| 634 | if(strlen($val['description'])>37) |
---|
| 635 | { |
---|
| 636 | $text=substr($val['description'],0,34)."..."; |
---|
| 637 | } |
---|
| 638 | else |
---|
| 639 | { |
---|
| 640 | $text=$val['description']; |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | $template_questions_list_values[] = $val['question_num'].".".$num; |
---|
| 644 | $template_questions_list_labels[] = "[".$num."] ".$text; |
---|
| 645 | |
---|
| 646 | $num++; |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | // block : translations |
---|
| 650 | $template_translations_list_values=array(); |
---|
| 651 | $template_translations_list_labels=array(); |
---|
| 652 | foreach($poll_languages as $val) |
---|
| 653 | { |
---|
| 654 | if($val != $default_values['default_lang']) |
---|
| 655 | { |
---|
| 656 | $template_translations_list_values[]=$val; |
---|
| 657 | $template_translations_list_labels[]=$languages[$val]; |
---|
| 658 | } |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | $template->assign('mypolls_questions_list_values', $template_questions_list_values); |
---|
| 662 | $template->assign('mypolls_questions_list_labels', $template_questions_list_labels); |
---|
| 663 | $template->assign('mypolls_translations_list_values', $template_translations_list_values); |
---|
| 664 | $template->assign('mypolls_translations_list_labels', $template_translations_list_labels); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | $template_datas["MYPOLLS_TITLE"] = l10n('mypolls_title_'.$access_type); |
---|
| 668 | |
---|
| 669 | $template->assign('mypolls_language_list_values', $template_language_list_values); |
---|
| 670 | $template->assign('mypolls_language_list_labels', $template_language_list_labels); |
---|
| 671 | $template->assign('mypolls_language_selected', $template_language_selected); |
---|
| 672 | $template->assign('mypolls_display_list_values', $template_display_list_values); |
---|
| 673 | $template->assign('mypolls_display_list_labels', $template_display_list_labels); |
---|
| 674 | $template->assign('mypolls_display_selected', $template_display_selected); |
---|
| 675 | $template->assign('datas', $template_datas); |
---|
| 676 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 677 | } //display_cm_page0 |
---|
| 678 | |
---|
| 679 | |
---|
| 680 | |
---|
| 681 | /* |
---|
| 682 | display other pages to create/modify a poll (poll's questions) |
---|
| 683 | page can be acceded : |
---|
| 684 | - when poll is created (no default_values) |
---|
| 685 | - when poll is created but with an error (default_values are form's values) |
---|
| 686 | - when poll is modified (default_values are database values) |
---|
| 687 | - when poll is modified but with an error (default_values are form's values) |
---|
| 688 | |
---|
| 689 | $access_type = "create", "modify" |
---|
| 690 | */ |
---|
| 691 | protected function display_cm_pagen($step, $poll_id, $default_values=array(), $access_type = "create") |
---|
| 692 | { |
---|
| 693 | global $template; |
---|
| 694 | |
---|
| 695 | $template->set_filename('body_page', |
---|
| 696 | dirname($this->filelocation).'/admin/plugin_admin_create2.tpl'); |
---|
| 697 | |
---|
| 698 | //$step format : id.num |
---|
| 699 | $steps=explode(".", $step); |
---|
| 700 | |
---|
| 701 | $template_datas["MYPOLLS_TITLE"] = l10n('mypolls_title_'.$access_type)." - ".l10n('mypolls_cm_question')." ".$steps[1]; |
---|
| 702 | $template_datas['MYPOLLS_STEP_VALUE'] = $steps[0]; |
---|
| 703 | $template_datas['MYPOLLS_ATT_ID'] = $poll_id; |
---|
| 704 | |
---|
| 705 | if($access_type=='create') |
---|
| 706 | { |
---|
| 707 | $template_datas['MYPOLLS_ICN_HIDDEN'] = 'visibility:hidden;'; |
---|
| 708 | } |
---|
| 709 | else |
---|
| 710 | { |
---|
| 711 | $template_datas['MYPOLLS_LNK_VIEW'] = $this->page_link.'&f_tabsheet=polls&action=view&fmypolls_att_id='.$poll_id; |
---|
| 712 | $template_datas['MYPOLLS_LNK_MODIFY'] = $this->page_link.'&f_tabsheet=polls&action=modify&fmypolls_att_id='.$poll_id; |
---|
| 713 | } |
---|
| 714 | $template_datas['MYPOLLS_ACTION'] = $access_type; |
---|
| 715 | |
---|
| 716 | if(count($default_values)==0) |
---|
| 717 | { |
---|
| 718 | $default_values=array( |
---|
| 719 | 'default_lang' => $_REQUEST['fmypolls_att_default_lang'], |
---|
| 720 | 'description' => '', |
---|
| 721 | 'question_type' => $this->my_config['mypolls_question_type_default'], |
---|
| 722 | 'multi_max_answers' => $this->my_config['mypolls_multi_max_answers_default'], |
---|
| 723 | 'answ0' => '', |
---|
| 724 | 'answ1' => '', |
---|
| 725 | 'counter_answers' => '1' |
---|
| 726 | ); |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | $template_datas['MYPOLLS_ATT_DESCRIPTION'] = $default_values['description']; |
---|
| 730 | $template_datas['MYPOLLS_ATT_MULTI_MAX_ANSWERS'] = $default_values['multi_max_answers']; |
---|
| 731 | $template_datas['MYPOLLS_NEXT_QUESTION'] = $default_values['counter_answers']+1; |
---|
| 732 | |
---|
| 733 | //poll's main language selection |
---|
| 734 | $languages=get_languages(); |
---|
| 735 | $template_datas['MYPOLLS_ATT_LANG'] = $default_values['default_lang']; |
---|
| 736 | $template_language_list_values=array(); |
---|
| 737 | $template_language_list_labels=array(); |
---|
| 738 | $template_language_list_values[]=$default_values['default_lang']; |
---|
| 739 | $template_language_list_labels[]=$languages[$default_values['default_lang']]; |
---|
| 740 | $template_language_selected[]=$default_values['default_lang']; |
---|
| 741 | |
---|
| 742 | //poll's type of display (one page for all question / a page per question) |
---|
| 743 | $template_question_type_list_values=array(); |
---|
| 744 | $template_question_type_list_labels=array(); |
---|
| 745 | $template_question_type_selected=$default_values['question_type']; |
---|
| 746 | for($i=0;$i<count($this->questions_types);$i++) |
---|
| 747 | { |
---|
| 748 | $template_question_type_list_values[]=$this->questions_types[$i]; |
---|
| 749 | $template_question_type_list_labels[]=l10n('mypolls_question_'.$this->questions_types[$i]); |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | //poll's answers |
---|
| 753 | $init=""; |
---|
| 754 | foreach($default_values as $key => $val) |
---|
| 755 | { |
---|
| 756 | if(substr($key,0,4)=="answ") |
---|
| 757 | { |
---|
| 758 | $init.="add_answer('".$val."', ".substr($key,4).");"; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | $template_datas['MYPOLLS_INIT_ANSWERS_LIST'] = $init; |
---|
| 762 | |
---|
| 763 | if($access_type=='create') |
---|
| 764 | { |
---|
| 765 | $template_datas['mypolls_en_creation'] = 'yes'; |
---|
| 766 | } |
---|
| 767 | elseif($access_type=='modify') |
---|
| 768 | { |
---|
| 769 | //modify poll, display specifics block for actions |
---|
| 770 | $template_datas['mypolls_en_modification'] = 'yes'; |
---|
| 771 | } |
---|
| 772 | elseif($access_type=='adding') |
---|
| 773 | { |
---|
| 774 | //add a question (modify poll)), display specifics block for actions |
---|
| 775 | $template_datas['mypolls_adding_question'] = 'yes'; |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | $template->assign('datas', $template_datas); |
---|
| 779 | $template->assign('mypolls_language_list_values', $template_language_list_values); |
---|
| 780 | $template->assign('mypolls_language_list_labels', $template_language_list_labels); |
---|
| 781 | $template->assign('mypolls_language_selected', $template_language_selected); |
---|
| 782 | $template->assign('mypolls_question_type_list_values', $template_question_type_list_values); |
---|
| 783 | $template->assign('mypolls_question_type_list_labels', $template_question_type_list_labels); |
---|
| 784 | $template->assign('mypolls_question_type_selected', $template_question_type_selected); |
---|
| 785 | |
---|
| 786 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 787 | } //display_cm_pagen |
---|
| 788 | |
---|
| 789 | |
---|
| 790 | /* |
---|
| 791 | display translation page |
---|
| 792 | */ |
---|
| 793 | protected function display_translation_page($poll_id, $lang="", $access_type="adding") |
---|
| 794 | { |
---|
| 795 | global $template, $user, $page; |
---|
| 796 | |
---|
| 797 | |
---|
| 798 | $template->set_filename('body_page', |
---|
| 799 | dirname($this->filelocation).'/admin/plugin_admin_translate.tpl'); |
---|
| 800 | |
---|
| 801 | |
---|
| 802 | if($access_type=="adding") |
---|
| 803 | { |
---|
| 804 | } |
---|
| 805 | else |
---|
| 806 | { |
---|
| 807 | $template_datas['MYPOLLS_LANG_DISABLED'] = ' disabled'; |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | $poll_langs=$this->get_poll_languages($poll_id); |
---|
| 811 | $poll_dlang=$this->get_poll_values($poll_id); |
---|
| 812 | $poll_tolang=$this->get_poll_values($poll_id, $lang); |
---|
| 813 | $languages=get_languages(); |
---|
| 814 | |
---|
| 815 | $template_langto_list_values=array(); |
---|
| 816 | $template_langto_list_labels=array(); |
---|
| 817 | $template_langto_selected=$lang; |
---|
| 818 | |
---|
| 819 | // initialize "to lang" list |
---|
| 820 | foreach($languages as $key => $val) |
---|
| 821 | { |
---|
| 822 | if($key!=$poll_dlang['default_lang']) |
---|
| 823 | { |
---|
| 824 | if((($access_type=="adding")&&(!in_array($key, $poll_langs)))||($access_type=="modify")) |
---|
| 825 | { |
---|
| 826 | $template_langto_list_values[]=$key; |
---|
| 827 | $template_langto_list_labels[]=$val; |
---|
| 828 | } |
---|
| 829 | } |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | $questions_dlang=$this->get_poll_questions($poll_id); |
---|
| 833 | $questions_tolang=$this->get_poll_questions($poll_id, "", $lang); |
---|
| 834 | $numq=1; |
---|
| 835 | $template_questions_list=array(); |
---|
| 836 | foreach($questions_dlang as $key => $val) |
---|
| 837 | { |
---|
| 838 | $template_answers_list=array(); |
---|
| 839 | $numa=1; |
---|
| 840 | $answers_dlang=$this->get_poll_answers($poll_id, $val['question_num']); |
---|
| 841 | $answers_tolang=$this->get_poll_answers($poll_id, $val['question_num'], $lang); |
---|
| 842 | foreach($answers_dlang as $key2 => $val2) |
---|
| 843 | { |
---|
| 844 | $template_answers_list[]=array( |
---|
| 845 | 'NUMANSWER' => $numa, |
---|
| 846 | 'IDANSWER' => $val['question_num']."_".$val2['answer_num'], |
---|
| 847 | //from lang |
---|
| 848 | 'ANSWER' => $val2['answer'], |
---|
| 849 | //to lang |
---|
| 850 | 'TTO_ANSWER' => isset($answers_tolang[$key2]['answer'])?$answers_tolang[$key2]['answer']:$val2['answer'] |
---|
| 851 | ); |
---|
| 852 | |
---|
| 853 | $numa++; |
---|
| 854 | } |
---|
| 855 | |
---|
| 856 | $template_questions_list[]=array( |
---|
| 857 | 'NUMQUESTION' => $numq, |
---|
| 858 | 'IDQUESTION' => $val['question_num'], |
---|
| 859 | //from lang |
---|
| 860 | 'DESCRIPTION' => $val['description'], |
---|
| 861 | //to lang |
---|
| 862 | 'TTO_DESCRIPTION' => isset($questions_tolang[$key]['description'])?$questions_tolang[$key]['description']:$val['description'], |
---|
| 863 | 'answers' => $template_answers_list |
---|
| 864 | ); |
---|
| 865 | |
---|
| 866 | $numq++; |
---|
| 867 | } |
---|
| 868 | |
---|
| 869 | if($access_type=='adding') |
---|
| 870 | { |
---|
| 871 | $template_datas['mypolls_add_translation'] = 'yes'; |
---|
| 872 | } |
---|
| 873 | elseif($access_type=='modify') |
---|
| 874 | { |
---|
| 875 | $template_datas['mypolls_modify_translation'] = 'yes'; |
---|
| 876 | } |
---|
| 877 | |
---|
| 878 | $template_datas["MYPOLLS_TITLE"] = l10n('mypolls_title_translation_'.$access_type); |
---|
| 879 | $template_datas['MYPOLLS_ATT_ID'] = $poll_id; |
---|
| 880 | $template_datas['MYPOLLS_ACTION'] = $access_type; |
---|
| 881 | $template_datas['MYPOLLS_LNK_VIEW'] = $this->page_link.'&f_tabsheet=polls&action=view&fmypolls_att_id='.$poll_id; |
---|
| 882 | $template_datas['MYPOLLS_LNK_MODIFY'] = $this->page_link.'&f_tabsheet=polls&action=modify&fmypolls_att_id='.$poll_id; |
---|
| 883 | $template_datas['MYPOLLS_CHARSET'] = substr($user['language'], 6); |
---|
| 884 | $template_datas['MYPOLLS_ATT_TITLE'] = $poll_dlang['title']; |
---|
| 885 | $template_datas['MYPOLLS_ATT_DESCRIPTION'] = $poll_dlang['description']; |
---|
| 886 | $template_datas['MYPOLLS_ATT_AFTER_VOTE_TEXT'] = $poll_dlang['after_vote_text']; |
---|
| 887 | $template_datas['MYPOLLS_TRANS_FROM'] = $poll_dlang['default_lang']; |
---|
| 888 | $template_datas['MYPOLLS_TRANS_FROM_TEXT'] = $languages[$poll_dlang['default_lang']]; |
---|
| 889 | $template_datas['MYPOLLS_ATT_TTO_TITLE'] = $poll_tolang['title']; |
---|
| 890 | $template_datas['MYPOLLS_ATT_TTO_DESCRIPTION'] = $poll_tolang['description']; |
---|
| 891 | $template_datas['MYPOLLS_ATT_TTO_AFTER_VOTE_TEXT'] = $poll_tolang['after_vote_text']; |
---|
| 892 | |
---|
| 893 | $template->assign('datas', $template_datas); |
---|
| 894 | $template->assign('mypolls_langto_list_values', $template_langto_list_values); |
---|
| 895 | $template->assign('mypolls_langto_list_labels', $template_langto_list_labels); |
---|
| 896 | $template->assign('mypolls_langto_selected', $template_langto_selected); |
---|
| 897 | $template->assign('questions', $template_questions_list); |
---|
| 898 | |
---|
| 899 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 900 | }//display_translation_page |
---|
| 901 | |
---|
| 902 | |
---|
| 903 | /* |
---|
| 904 | display view page |
---|
| 905 | */ |
---|
| 906 | protected function display_view($poll_id, $lang="") |
---|
| 907 | { |
---|
| 908 | global $template; |
---|
| 909 | |
---|
| 910 | $template->set_filename('body_page', |
---|
| 911 | dirname($this->filelocation).'/admin/plugin_admin_view.tpl'); |
---|
| 912 | |
---|
| 913 | $poll_langs=$this->get_poll_languages($poll_id); |
---|
| 914 | $poll_values=$this->get_poll_values($poll_id, $lang); |
---|
| 915 | $languages=get_languages(); |
---|
| 916 | |
---|
| 917 | if($lang=="") |
---|
| 918 | { |
---|
| 919 | $lang=$poll_values['default_lang']; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | |
---|
| 923 | $template_langs_list_values=array(); |
---|
| 924 | $template_langs_list_labels=array(); |
---|
| 925 | $template_langs_selected=$lang; |
---|
| 926 | |
---|
| 927 | // initialize "view langs" list |
---|
| 928 | foreach($poll_langs as $key => $val) |
---|
| 929 | { |
---|
| 930 | $template_langs_list_values[]=$val; |
---|
| 931 | $template_langs_list_labels[]=$languages[$val]; |
---|
| 932 | } |
---|
| 933 | $users=new users($poll_values['allowed_users']); |
---|
| 934 | $users->set_allowed('admin', false); |
---|
| 935 | $groups=new groups($poll_values['allowed_groups']); |
---|
| 936 | |
---|
| 937 | |
---|
| 938 | $this->display_results_block($poll_id, $lang, $poll_values); |
---|
| 939 | |
---|
| 940 | $template_datas['MYPOLLS_TITLE'] = l10n('mypolls_title_view'); |
---|
| 941 | $template_datas['MYPOLLS_ATT_ID'] = $poll_id; |
---|
| 942 | $template_datas['MYPOLLS_LNK_MODIFY'] = $this->page_link.'&f_tabsheet=polls&action=modify&fmypolls_att_id='.$poll_id; |
---|
| 943 | $template_datas['MYPOLLS_AJAX_URL_POLL_VOTER_LIST'] = $this->page_link.'&ajaxfct=poll_user_list&poll_id='.$poll_id.'&vpage='; |
---|
| 944 | $template_datas['MYPOLLS_AJAX_URL_POLL_COMMENT_LIST'] = $this->page_link.'&ajaxfct=poll_comment_list&poll_id='.$poll_id.'&vpage='; |
---|
| 945 | $template_datas['MYPOLLS_AJAX_URL_POLL_DELETE_COMMENT'] = $this->page_link.'&ajaxfct=poll_delete_comment&poll_id='.$poll_id.'&comment_id='; |
---|
| 946 | $template_datas['MYPOLLS_CHARSET'] = substr($lang, 6); |
---|
| 947 | $template_datas['MYPOLLS_ATT_TITLE'] = $poll_values['title']; |
---|
| 948 | $template_datas['MYPOLLS_ATT_DESCRIPTION'] = html_entity_decode($poll_values['description'], ENT_QUOTES); |
---|
| 949 | $template_datas['MYPOLLS_ATT_AFTER_VOTE_TEXT'] = html_entity_decode($poll_values['after_vote_text'], ENT_QUOTES); |
---|
| 950 | $template_datas['MYPOLLS_ATT_DATE'] = $poll_values['date']; |
---|
| 951 | $template_datas['MYPOLLS_ATT_ENABLED'] = l10n('mypolls_yesno_'.$poll_values['enabled']); |
---|
| 952 | $template_datas['MYPOLLS_ATT_VISIBLE'] = l10n('mypolls_yesno_'.$poll_values['visible']); |
---|
| 953 | $template_datas['MYPOLLS_ATT_ALLOW_COMMENT'] = l10n('mypolls_yesno_'.$poll_values['allow_comment']); |
---|
| 954 | $template_datas['MYPOLLS_ATT_SHOW_COMMENTS'] = l10n('mypolls_yesno_'.$poll_values['show_comments']); |
---|
| 955 | $template_datas['MYPOLLS_ATT_ALLOWED_USERS'] = $users->html_view(", ", l10n('mypolls_allowed_users_empty')); |
---|
| 956 | $template_datas['MYPOLLS_ATT_ALLOWED_GROUPS'] = $groups->html_view(", ", l10n('mypolls_allowed_groups_empty')); |
---|
| 957 | $template_datas['MYPOLLS_ATT_NB_QUESTIONS'] = $poll_values['nb_questions']; |
---|
| 958 | $template_datas['MYPOLLS_ATT_TOTAL_VOTES'] = $poll_values['total_votes']; |
---|
| 959 | $template_datas['MYPOLLS_ATT_LAST_VOTE'] = ($poll_values['last_vote']=="0000-00-00 00:00:00")?l10n('mypolls_result_no_vote'):$poll_values['last_vote']; |
---|
| 960 | $template_datas['MYPOLLS_ATT_VISIT_WITHOUT_VOTE'] = $poll_values['visit_without_vote']; |
---|
| 961 | $template_datas['MYPOLLS_ATT_VISIT_AFTER_VOTE'] = $poll_values['visit_after_vote']; |
---|
| 962 | $template_datas['MYPOLLS_ATT_DISPLAY_TYPE'] = strtolower(l10n('mypolls_display_'.$poll_values['display_type'])); |
---|
| 963 | $template_datas['MYPOLLS_ATT_PUBLIC_RESULTS'] = $poll_values['public_results']; |
---|
| 964 | |
---|
| 965 | $template->assign('datas', $template_datas); |
---|
| 966 | $template->assign('mypolls_langs_list_values', $template_langs_list_values); |
---|
| 967 | $template->assign('mypolls_langs_list_labels', $template_langs_list_labels); |
---|
| 968 | $template->assign('mypolls_langs_selected', $template_langs_selected); |
---|
| 969 | |
---|
| 970 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 971 | } //display_view |
---|
| 972 | |
---|
| 973 | /* |
---|
| 974 | display config page |
---|
| 975 | */ |
---|
| 976 | protected function display_config() |
---|
| 977 | { |
---|
| 978 | global $template; |
---|
| 979 | |
---|
| 980 | $template->set_filename('body_page', |
---|
| 981 | dirname($this->filelocation).'/admin/plugin_admin_config.tpl'); |
---|
| 982 | |
---|
| 983 | //poll's type of display (one page for all question / a page per question) |
---|
| 984 | $template_display_list_values=array(); |
---|
| 985 | $template_display_list_labels=array(); |
---|
| 986 | $template_display_selected=$this->my_config['mypolls_display_type_default']; |
---|
| 987 | foreach($this->display_types as $val) |
---|
| 988 | { |
---|
| 989 | $template_display_list_values[]=$val; |
---|
| 990 | $template_display_list_labels[]=l10n('mypolls_display_'.$val); |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | //langs list & texts |
---|
| 994 | |
---|
| 995 | $template_language_list=array(); |
---|
| 996 | $template_language_list_values=array(); |
---|
| 997 | $template_language_list_labels=array(); |
---|
| 998 | $template_language_selected=str2url(get_default_language()); |
---|
| 999 | $languages=get_languages(); |
---|
| 1000 | foreach($languages as $key => $val) |
---|
| 1001 | { |
---|
| 1002 | $template_language_list_values[]=str2url($key); |
---|
| 1003 | $template_language_list_labels[]=$val; |
---|
| 1004 | |
---|
| 1005 | $template_language_list[]=array( |
---|
| 1006 | 'LANG' => str2url($key), |
---|
| 1007 | 'MENUBARTIT' => $this->my_config['mypolls_menubar_title'][$key], |
---|
| 1008 | 'GENTEXUSER' => $this->my_config['mypolls_generic_text_users'][$key], |
---|
| 1009 | 'GENTEXGUEST' => $this->my_config['mypolls_generic_text_guests'][$key], |
---|
| 1010 | 'NOTPUBRESTEX' => $this->my_config['mypolls_not_public_results'][$key] |
---|
| 1011 | ); |
---|
| 1012 | } |
---|
| 1013 | $template_datas["MYPOLLS_TITLE"] = l10n('mypolls_title_config'); |
---|
| 1014 | |
---|
| 1015 | $template_datas['MYPOLLS_CFG_COLOR_BARS'] = $this->my_config['mypolls_color_bars']; |
---|
| 1016 | $template_datas['MYPOLLS_CFG_MAXBARWIDTH'] = $this->my_config['mypolls_maxbarwidth']; |
---|
| 1017 | $template_datas['MYPOLLS_CFG_ADMINCOLOR'] = $this->my_config['mypolls_admincolor']; |
---|
| 1018 | $template_datas['MYPOLLS_CFG_MOUSEOVERCOLOR'] = $this->my_config['mypolls_mouseovercolor']; |
---|
| 1019 | $template_datas['MYPOLLS_CFG_NBUSER_PER_PAGE'] = $this->my_config['mypolls_nbuser_per_page']; |
---|
| 1020 | $template_datas['MYPOLLS_CFG_NBCOMMENT_PER_PAGE'] = $this->my_config['mypolls_nbcomment_per_page']; |
---|
| 1021 | |
---|
| 1022 | $template->assign('datas', $template_datas); |
---|
| 1023 | $template->assign('mypolls_language_list', $template_language_list); |
---|
| 1024 | $template->assign('mypolls_language_list_values', $template_language_list_values); |
---|
| 1025 | $template->assign('mypolls_language_list_labels', $template_language_list_labels); |
---|
| 1026 | $template->assign('mypolls_language_selected', $template_language_selected); |
---|
| 1027 | $template->assign('mypolls_display_list_values', $template_display_list_values); |
---|
| 1028 | $template->assign('mypolls_display_list_labels', $template_display_list_labels); |
---|
| 1029 | $template->assign('mypolls_display_selected', $template_display_selected); |
---|
| 1030 | |
---|
| 1031 | $template->assign_var_from_handle('MYPOLLS_BODY_PAGE', 'body_page'); |
---|
| 1032 | } //display_config |
---|
| 1033 | |
---|
| 1034 | /* |
---|
| 1035 | manage adviser profile |
---|
| 1036 | return true if user is adviser |
---|
| 1037 | */ |
---|
| 1038 | protected function adviser_abort() |
---|
| 1039 | { |
---|
| 1040 | if(is_adviser()) |
---|
| 1041 | { |
---|
| 1042 | $this->display_result(l10n("mypolls_adviser_not_allowed"), false); |
---|
| 1043 | return(true); |
---|
| 1044 | } |
---|
| 1045 | return(false); |
---|
| 1046 | } |
---|
| 1047 | |
---|
| 1048 | /* |
---|
| 1049 | deactivate a poll |
---|
| 1050 | */ |
---|
| 1051 | protected function deactivate_poll($poll_id) |
---|
| 1052 | { |
---|
| 1053 | $sql="UPDATE ".$this->tables['polls']." |
---|
| 1054 | SET enabled = 'n' |
---|
| 1055 | WHERE id = '".$poll_id."'"; |
---|
| 1056 | $result=pwg_query($sql); |
---|
| 1057 | return($result); |
---|
| 1058 | } |
---|
| 1059 | |
---|
| 1060 | /* |
---|
| 1061 | create a poll |
---|
| 1062 | if $page = 0, create general nfo else create question |
---|
| 1063 | */ |
---|
| 1064 | protected function do_create_poll($step) |
---|
| 1065 | { |
---|
| 1066 | if($step==0) |
---|
| 1067 | { |
---|
| 1068 | //step 0 : create root caracteristics of poll |
---|
| 1069 | $groups = new groups(); |
---|
| 1070 | $users = new users(); |
---|
| 1071 | foreach($_REQUEST as $key => $val) |
---|
| 1072 | { |
---|
| 1073 | if((substr($key, 0, 28)=='fmypolls_att_allowed_groups_') and ($val=="on")) |
---|
| 1074 | { |
---|
| 1075 | $groups->set_allowed(substr($key,28),true); |
---|
| 1076 | } |
---|
| 1077 | |
---|
| 1078 | if((substr($key, 0, 27)=='fmypolls_att_allowed_users_') and ($val=="on")) |
---|
| 1079 | { |
---|
| 1080 | $users->set_allowed(substr($key,27),true); |
---|
| 1081 | } |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | $values = array( |
---|
| 1085 | 'allowed_users' => $users->get_alloweds('id'), |
---|
| 1086 | 'allowed_groups' => $groups->get_alloweds('id'), |
---|
| 1087 | 'visible' => $_REQUEST['fmypolls_att_visible'], |
---|
| 1088 | 'enabled' => $_REQUEST['fmypolls_att_enabled'], |
---|
| 1089 | 'allow_comment' => $_REQUEST['fmypolls_att_allow_comment'], |
---|
| 1090 | 'show_comments' => $_REQUEST['fmypolls_att_show_comments'], |
---|
| 1091 | 'color_bars' => $_REQUEST['fmypolls_att_color_bars'], |
---|
| 1092 | 'display_type' => $_REQUEST['fmypolls_att_display_type'], |
---|
| 1093 | 'default_lang' => $_REQUEST['fmypolls_att_default_lang'], |
---|
| 1094 | 'public_results' => $_REQUEST['fmypolls_att_public_results'] |
---|
| 1095 | ); |
---|
| 1096 | $poll_id=$this->create_poll($values); |
---|
| 1097 | if($poll_id>0) |
---|
| 1098 | { |
---|
| 1099 | $values = array( |
---|
| 1100 | 'lang' => $_REQUEST['fmypolls_att_default_lang'], |
---|
| 1101 | 'title' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_title']), ENT_QUOTES), |
---|
| 1102 | 'description' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_description']), ENT_QUOTES), |
---|
| 1103 | 'after_vote_text' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_after_vote_text']), ENT_QUOTES), |
---|
| 1104 | ); |
---|
| 1105 | if($this->create_poll_lang($poll_id, $values)) |
---|
| 1106 | { |
---|
| 1107 | return($poll_id); |
---|
| 1108 | } |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | else |
---|
| 1112 | { //step >0 : create questions |
---|
| 1113 | $poll_id=$_REQUEST['fmypolls_att_id']; |
---|
| 1114 | $values = array( |
---|
| 1115 | 'id_poll' => $poll_id, |
---|
| 1116 | 'question_num' => $step, |
---|
| 1117 | 'question_type' => $_REQUEST['fmypolls_att_question_type'], |
---|
| 1118 | 'multi_max_answers' => isset($_REQUEST['fmypolls_att_multi_max_answers']) ? $_REQUEST['fmypolls_att_multi_max_answers'] : '0' |
---|
| 1119 | ); |
---|
| 1120 | if($this->create_poll_questions($values)) |
---|
| 1121 | { |
---|
| 1122 | $values = array( |
---|
| 1123 | 'id_poll' => $poll_id, |
---|
| 1124 | 'id_question' => $step, |
---|
| 1125 | 'lang' => $_REQUEST['fmypolls_att_default_lang'], |
---|
| 1126 | 'description' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_description']), ENT_QUOTES) |
---|
| 1127 | ); |
---|
| 1128 | if($this->create_poll_questions_lang($values)) |
---|
| 1129 | { |
---|
| 1130 | foreach($_REQUEST as $key => $val) |
---|
| 1131 | { |
---|
| 1132 | if((substr($key, 0, 17)=='fmypolls_att_answ') and ($val!='')) |
---|
| 1133 | { |
---|
| 1134 | $values = array( |
---|
| 1135 | 'id_poll' => $poll_id, |
---|
| 1136 | 'id_question' => $step, |
---|
| 1137 | 'answer_num' => substr($key,17), |
---|
| 1138 | '0' |
---|
| 1139 | ); |
---|
| 1140 | if($this->create_poll_answers($values)) |
---|
| 1141 | { |
---|
| 1142 | $values = array( |
---|
| 1143 | 'id_poll' => $poll_id, |
---|
| 1144 | 'id_question' => $step, |
---|
| 1145 | 'id_answer' => substr($key,17), |
---|
| 1146 | 'lang' => $_REQUEST['fmypolls_att_default_lang'], |
---|
| 1147 | 'answer' => htmlspecialchars(stripslashes($val), ENT_QUOTES), |
---|
| 1148 | 'nb_votes' => '0' |
---|
| 1149 | ); |
---|
| 1150 | if(!$this->create_poll_answers_lang($values)) |
---|
| 1151 | { |
---|
| 1152 | return(false); |
---|
| 1153 | } |
---|
| 1154 | } |
---|
| 1155 | } |
---|
| 1156 | } |
---|
| 1157 | } |
---|
| 1158 | return($poll_id); |
---|
| 1159 | } |
---|
| 1160 | } |
---|
| 1161 | return(false); |
---|
| 1162 | } //do_create_poll |
---|
| 1163 | |
---|
| 1164 | /* |
---|
| 1165 | modify a poll |
---|
| 1166 | if $page = 0, modify general nfo else modify question |
---|
| 1167 | */ |
---|
| 1168 | protected function do_modify_poll($step, $poll_id) |
---|
| 1169 | { |
---|
| 1170 | if($step==0) |
---|
| 1171 | { |
---|
| 1172 | //step 0 : modify root caracteristics of poll |
---|
| 1173 | $groups = new groups(); |
---|
| 1174 | $users = new users(); |
---|
| 1175 | foreach($_REQUEST as $key => $val) |
---|
| 1176 | { |
---|
| 1177 | if((substr($key, 0, 28)=='fmypolls_att_allowed_groups_') and ($val=="on")) |
---|
| 1178 | { |
---|
| 1179 | $groups->set_allowed(substr($key,28),true); |
---|
| 1180 | } |
---|
| 1181 | |
---|
| 1182 | if((substr($key, 0, 27)=='fmypolls_att_allowed_users_') and ($val=="on")) |
---|
| 1183 | { |
---|
| 1184 | $users->set_allowed(substr($key,27),true); |
---|
| 1185 | } |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | $values = array( |
---|
| 1189 | 'allowed_users' => $users->get_alloweds('id'), |
---|
| 1190 | 'allowed_groups' => $groups->get_alloweds('id'), |
---|
| 1191 | 'visible' => $_REQUEST['fmypolls_att_visible'], |
---|
| 1192 | 'enabled' => $_REQUEST['fmypolls_att_enabled'], |
---|
| 1193 | 'allow_comment' => $_REQUEST['fmypolls_att_allow_comment'], |
---|
| 1194 | 'show_comments' => $_REQUEST['fmypolls_att_show_comments'], |
---|
| 1195 | 'color_bars' => $_REQUEST['fmypolls_att_color_bars'], |
---|
| 1196 | 'display_type' => $_REQUEST['fmypolls_att_display_type'], |
---|
| 1197 | 'public_results' => $_REQUEST['fmypolls_att_public_results'] |
---|
| 1198 | ); |
---|
| 1199 | $result=$this->modify_poll($poll_id, $values); |
---|
| 1200 | if($result>0) |
---|
| 1201 | { |
---|
| 1202 | $values = array( |
---|
| 1203 | 'title' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_title']), ENT_QUOTES), |
---|
| 1204 | 'description' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_description']), ENT_QUOTES), |
---|
| 1205 | 'after_vote_text' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_after_vote_text']), ENT_QUOTES) |
---|
| 1206 | ); |
---|
| 1207 | if($this->modify_poll_lang($poll_id, $_REQUEST['fmypolls_att_default_lang'], $values)) |
---|
| 1208 | { |
---|
| 1209 | return($poll_id); |
---|
| 1210 | } |
---|
| 1211 | } |
---|
| 1212 | } |
---|
| 1213 | else |
---|
| 1214 | { //step >0 :modify questions |
---|
| 1215 | $poll_id=$_REQUEST['fmypolls_att_id']; |
---|
| 1216 | $values = array( |
---|
| 1217 | 'question_type' => $_REQUEST['fmypolls_att_question_type'], |
---|
| 1218 | 'multi_max_answers' => isset($_REQUEST['fmypolls_att_multi_max_answers']) ? $_REQUEST['fmypolls_att_multi_max_answers'] : '0' |
---|
| 1219 | ); |
---|
| 1220 | if($this->modify_poll_questions($poll_id, $step, $values)) |
---|
| 1221 | { |
---|
| 1222 | $values = array( |
---|
| 1223 | 'description' => htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_description']), ENT_QUOTES) |
---|
| 1224 | ); |
---|
| 1225 | if($this->modify_poll_questions_lang($poll_id, $step, $_REQUEST['fmypolls_att_default_lang'], $values)) |
---|
| 1226 | { |
---|
| 1227 | foreach($_REQUEST as $key => $val) |
---|
| 1228 | { |
---|
| 1229 | if((substr($key, 0, 17)=='fmypolls_att_answ')) |
---|
| 1230 | { |
---|
| 1231 | if($val=='') |
---|
| 1232 | { |
---|
| 1233 | if($this->delete_poll_answers($poll_id, $step, substr($key,17))) |
---|
| 1234 | { |
---|
| 1235 | if(!$this->delete_poll_answers_lang($poll_id, $step, substr($key,17))) |
---|
| 1236 | { |
---|
| 1237 | return(false); |
---|
| 1238 | } |
---|
| 1239 | } |
---|
| 1240 | } |
---|
| 1241 | else |
---|
| 1242 | { |
---|
| 1243 | $values = array( |
---|
| 1244 | 'answer' => htmlspecialchars(stripslashes($val), ENT_QUOTES) |
---|
| 1245 | ); |
---|
| 1246 | if(!$this->modify_poll_answers_lang($poll_id, $step, substr($key,17), $_REQUEST['fmypolls_att_default_lang'], $values)) |
---|
| 1247 | { |
---|
| 1248 | return(false); |
---|
| 1249 | } |
---|
| 1250 | } |
---|
| 1251 | } |
---|
| 1252 | } |
---|
| 1253 | } |
---|
| 1254 | return($poll_id); |
---|
| 1255 | } |
---|
| 1256 | } |
---|
| 1257 | return(false); |
---|
| 1258 | } //do_modify_poll |
---|
| 1259 | |
---|
| 1260 | |
---|
| 1261 | /* |
---|
| 1262 | delete a poll's question |
---|
| 1263 | */ |
---|
| 1264 | protected function do_delete_question($step, $poll_id) |
---|
| 1265 | { |
---|
| 1266 | if($this->delete_poll_questions($poll_id, $step)) |
---|
| 1267 | { |
---|
| 1268 | if($this->delete_poll_questions_lang($poll_id, $step)) |
---|
| 1269 | { |
---|
| 1270 | if($this->delete_poll_answers($poll_id, $step)) |
---|
| 1271 | { |
---|
| 1272 | if($this->delete_poll_answers_lang($poll_id, $step)) |
---|
| 1273 | { |
---|
| 1274 | return($poll_id); |
---|
| 1275 | } |
---|
| 1276 | } |
---|
| 1277 | } |
---|
| 1278 | } |
---|
| 1279 | return(false); |
---|
| 1280 | } |
---|
| 1281 | |
---|
| 1282 | /* |
---|
| 1283 | delete a poll |
---|
| 1284 | */ |
---|
| 1285 | protected function do_delete_poll($poll_id) |
---|
| 1286 | { |
---|
| 1287 | if($this->delete_poll($poll_id)) |
---|
| 1288 | { |
---|
| 1289 | if($this->delete_poll_lang($poll_id)) |
---|
| 1290 | { |
---|
| 1291 | if($this->do_delete_question("", $poll_id)) |
---|
| 1292 | { |
---|
| 1293 | return($poll_id); |
---|
| 1294 | } |
---|
| 1295 | } |
---|
| 1296 | } |
---|
| 1297 | return(false); |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | /* |
---|
| 1301 | translate a poll (add / modify) |
---|
| 1302 | nfo are from $_REQUEST global var |
---|
| 1303 | */ |
---|
| 1304 | protected function do_translate_poll($poll_id) |
---|
| 1305 | { |
---|
| 1306 | $sql="REPLACE INTO ".$this->tables['polls_lang']." VALUES ( |
---|
| 1307 | '".$poll_id."', |
---|
| 1308 | '".$_REQUEST['fmypolls_trans_to']."', |
---|
| 1309 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_tto_title']), ENT_QUOTES)."', |
---|
| 1310 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_tto_description']), ENT_QUOTES)."', |
---|
| 1311 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_tto_after_vote_text']), ENT_QUOTES)."' |
---|
| 1312 | )"; |
---|
| 1313 | if(pwg_query($sql)) |
---|
| 1314 | { |
---|
| 1315 | $poll_questions=$this->get_poll_questions($poll_id); |
---|
| 1316 | foreach($poll_questions as $key => $val) |
---|
| 1317 | { |
---|
| 1318 | $sql="REPLACE INTO ".$this->tables['polls_questions_lang']." VALUES ( |
---|
| 1319 | '".$poll_id."', |
---|
| 1320 | '".$val['question_num']."', |
---|
| 1321 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_trans_to']), ENT_QUOTES)."', |
---|
| 1322 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_tto_qdescription_'.$val['question_num']]), ENT_QUOTES)."' |
---|
| 1323 | )"; |
---|
| 1324 | if(pwg_query($sql)) |
---|
| 1325 | { |
---|
| 1326 | $poll_answers=$this->get_poll_answers($poll_id, $val['question_num']); |
---|
| 1327 | $poll_danswers=$this->get_poll_answers($poll_id, $val['question_num'],$_REQUEST['fmypolls_trans_to']); |
---|
| 1328 | foreach($poll_answers as $key2 => $val2) |
---|
| 1329 | { |
---|
| 1330 | if(isset($poll_danswers[$key2])) |
---|
| 1331 | { |
---|
| 1332 | $nbvotes=$poll_danswers[$key2]['nb_votes']; |
---|
| 1333 | } |
---|
| 1334 | else |
---|
| 1335 | { |
---|
| 1336 | $nbvotes=0; |
---|
| 1337 | } |
---|
| 1338 | $sql="REPLACE INTO ".$this->tables['polls_answers_lang']." VALUES ( |
---|
| 1339 | '".$poll_id."', |
---|
| 1340 | '".$val['question_num']."', |
---|
| 1341 | '".$val2['answer_num']."', |
---|
| 1342 | '".$_REQUEST['fmypolls_trans_to']."', |
---|
| 1343 | '".htmlspecialchars(stripslashes($_REQUEST['fmypolls_att_tto_adescription_'.$val['question_num']."_".$val2['answer_num']]), ENT_QUOTES)."', |
---|
| 1344 | '".$nbvotes."' |
---|
| 1345 | )"; |
---|
| 1346 | if(!pwg_query($sql)) |
---|
| 1347 | { |
---|
| 1348 | return(false); |
---|
| 1349 | } |
---|
| 1350 | } |
---|
| 1351 | } |
---|
| 1352 | else |
---|
| 1353 | { |
---|
| 1354 | return(false); |
---|
| 1355 | } |
---|
| 1356 | } |
---|
| 1357 | return(true); |
---|
| 1358 | } |
---|
| 1359 | return(false); |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | protected function do_delete_poll_translation($poll_id, $lang) |
---|
| 1363 | { |
---|
| 1364 | $sql="DELETE FROM ".$this->tables['polls_lang']." |
---|
| 1365 | WHERE id_poll = '".$poll_id."' |
---|
| 1366 | AND lang = '".$lang."' "; |
---|
| 1367 | if(pwg_query($sql)) |
---|
| 1368 | { |
---|
| 1369 | $sql="DELETE FROM ".$this->tables['polls_questions_lang']." |
---|
| 1370 | WHERE id_poll = '".$poll_id."' |
---|
| 1371 | AND lang = '".$lang."' "; |
---|
| 1372 | if(pwg_query($sql)) |
---|
| 1373 | { |
---|
| 1374 | $sql="DELETE FROM ".$this->tables['polls_answers_lang']." |
---|
| 1375 | WHERE id_poll = '".$poll_id."' |
---|
| 1376 | AND lang = '".$lang."' "; |
---|
| 1377 | if(pwg_query($sql)) |
---|
| 1378 | { |
---|
| 1379 | return(true); |
---|
| 1380 | } |
---|
| 1381 | } |
---|
| 1382 | } |
---|
| 1383 | return(false); |
---|
| 1384 | } |
---|
| 1385 | |
---|
| 1386 | /* --------------------------------------------------------------------------- |
---|
| 1387 | function to manage database manipulation |
---|
| 1388 | --------------------------------------------------------------------------- */ |
---|
| 1389 | |
---|
| 1390 | |
---|
| 1391 | /* |
---|
| 1392 | insert poll general info (no language needed) |
---|
| 1393 | input : an array of general values |
---|
| 1394 | return poll_id if OK, else -1 |
---|
| 1395 | */ |
---|
| 1396 | protected function create_poll($values) |
---|
| 1397 | { |
---|
| 1398 | $sql="INSERT INTO ".$this->tables['polls']." VALUES ( |
---|
| 1399 | '0', '".date('Y-m-d H:i:s')."', |
---|
| 1400 | '".$values['allowed_users']."', |
---|
| 1401 | '".$values['allowed_groups']."', |
---|
| 1402 | '".$values['visible']."', |
---|
| 1403 | '".$values['enabled']."', |
---|
| 1404 | '0', |
---|
| 1405 | '0000-00-00 00:00:00', |
---|
| 1406 | '0', |
---|
| 1407 | '0', |
---|
| 1408 | '".$values['allow_comment']."', |
---|
| 1409 | '".$values['show_comments']."', |
---|
| 1410 | '".$values['color_bars']."', |
---|
| 1411 | '0', |
---|
| 1412 | '".$values['display_type']."', |
---|
| 1413 | '".$values['default_lang']."', |
---|
| 1414 | '0', |
---|
| 1415 | '0', |
---|
| 1416 | '".$values['public_results']."' |
---|
| 1417 | )"; |
---|
| 1418 | $result=pwg_query($sql); |
---|
| 1419 | if($result) |
---|
| 1420 | { |
---|
| 1421 | return(mysql_insert_id()); |
---|
| 1422 | } |
---|
| 1423 | return(false); |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | /* |
---|
| 1427 | insert poll general info (langage needed) |
---|
| 1428 | input : poll_id, an array(lang, title, description, after_vote_text) |
---|
| 1429 | return 1 if OK, else -1 |
---|
| 1430 | */ |
---|
| 1431 | protected function create_poll_lang($poll_id, $values) |
---|
| 1432 | { |
---|
| 1433 | $sql="INSERT INTO ".$this->tables['polls_lang']." VALUES ( |
---|
| 1434 | '".$poll_id."', |
---|
| 1435 | '".$values['lang']."', |
---|
| 1436 | '".$values['title']."', |
---|
| 1437 | '".$values['description']."', |
---|
| 1438 | '".$values['after_vote_text']."' |
---|
| 1439 | )"; |
---|
| 1440 | $result=pwg_query($sql); |
---|
| 1441 | if(!$result) |
---|
| 1442 | { |
---|
| 1443 | return(false); |
---|
| 1444 | } |
---|
| 1445 | return($poll_id); |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | /* |
---|
| 1449 | insert poll question info (no language needed) |
---|
| 1450 | input : an array of general values |
---|
| 1451 | return poll_id if OK, else -1 |
---|
| 1452 | */ |
---|
| 1453 | protected function create_poll_questions($values) |
---|
| 1454 | { |
---|
| 1455 | $sql="INSERT INTO ".$this->tables['polls_questions']." VALUES ( |
---|
| 1456 | '".$values['id_poll']."', |
---|
| 1457 | '".$values['question_num']."', |
---|
| 1458 | '".$values['question_type']."', |
---|
| 1459 | '".$values['multi_max_answers']."', |
---|
| 1460 | '0', |
---|
| 1461 | '0' |
---|
| 1462 | )"; |
---|
| 1463 | $result=pwg_query($sql); |
---|
| 1464 | if($result) |
---|
| 1465 | { |
---|
| 1466 | $sql="UPDATE ".$this->tables['polls']." |
---|
| 1467 | SET nb_questions = nb_questions+1, |
---|
| 1468 | counter_questions = counter_questions+1 |
---|
| 1469 | WHERE id = '".$values['id_poll']."'"; |
---|
| 1470 | $result=pwg_query($sql); |
---|
| 1471 | if($result) |
---|
| 1472 | { |
---|
| 1473 | return($values['id_poll']); |
---|
| 1474 | } |
---|
| 1475 | } |
---|
| 1476 | return(false); |
---|
| 1477 | } |
---|
| 1478 | |
---|
| 1479 | /* |
---|
| 1480 | insert poll question info (language needed) |
---|
| 1481 | input : an array of general values |
---|
| 1482 | return poll_id if OK, else -1 |
---|
| 1483 | */ |
---|
| 1484 | protected function create_poll_questions_lang($values) |
---|
| 1485 | { |
---|
| 1486 | $sql="INSERT INTO ".$this->tables['polls_questions_lang']." VALUES ( |
---|
| 1487 | '".$values['id_poll']."', |
---|
| 1488 | '".$values['id_question']."', |
---|
| 1489 | '".$values['lang']."', |
---|
| 1490 | '".$values['description']."' |
---|
| 1491 | )"; |
---|
| 1492 | $result=pwg_query($sql); |
---|
| 1493 | if(!$result) |
---|
| 1494 | { |
---|
| 1495 | return(false); |
---|
| 1496 | } |
---|
| 1497 | return($values['id_poll']); |
---|
| 1498 | } |
---|
| 1499 | |
---|
| 1500 | /* |
---|
| 1501 | insert poll answers info (no language needed) |
---|
| 1502 | input : an array of general values |
---|
| 1503 | return poll_id if OK, else -1 |
---|
| 1504 | */ |
---|
| 1505 | protected function create_poll_answers($values) |
---|
| 1506 | { |
---|
| 1507 | $sql="INSERT INTO ".$this->tables['polls_answers']." VALUES ( |
---|
| 1508 | '".$values['id_poll']."', |
---|
| 1509 | '".$values['id_question']."', |
---|
| 1510 | '".$values['answer_num']."', |
---|
| 1511 | '0', |
---|
| 1512 | '0', |
---|
| 1513 | '0' |
---|
| 1514 | )"; |
---|
| 1515 | $result=pwg_query($sql); |
---|
| 1516 | if(!$result) |
---|
| 1517 | { |
---|
| 1518 | return(false); |
---|
| 1519 | } |
---|
| 1520 | //every answer created increment a counter on the question |
---|
| 1521 | //needed to maintain properly answers's id when modify/delete/add one |
---|
| 1522 | $sql="UPDATE ".$this->tables['polls_questions']." |
---|
| 1523 | SET counter_answers = counter_answers+1 |
---|
| 1524 | WHERE id_poll = '".$values['id_poll']."' |
---|
| 1525 | AND question_num = '".$values['id_question']."' "; |
---|
| 1526 | pwg_query($sql); |
---|
| 1527 | return($values['id_poll']); |
---|
| 1528 | } |
---|
| 1529 | |
---|
| 1530 | /* |
---|
| 1531 | insert poll question info (language needed) |
---|
| 1532 | input : an array of general values |
---|
| 1533 | return poll_id if OK, else -1 |
---|
| 1534 | */ |
---|
| 1535 | protected function create_poll_answers_lang($values) |
---|
| 1536 | { |
---|
| 1537 | $sql="INSERT INTO ".$this->tables['polls_answers_lang']." VALUES ( |
---|
| 1538 | '".$values['id_poll']."', |
---|
| 1539 | '".$values['id_question']."', |
---|
| 1540 | '".$values['id_answer']."', |
---|
| 1541 | '".$values['lang']."', |
---|
| 1542 | '".$values['answer']."', |
---|
| 1543 | '0' |
---|
| 1544 | )"; |
---|
| 1545 | $result=pwg_query($sql); |
---|
| 1546 | if(!$result) |
---|
| 1547 | { |
---|
| 1548 | return(false); |
---|
| 1549 | } |
---|
| 1550 | return($values['id_poll']); |
---|
| 1551 | } |
---|
| 1552 | |
---|
| 1553 | /* |
---|
| 1554 | initialise an array from database to prepare form |
---|
| 1555 | input : poll_id |
---|
| 1556 | return an array if OK, else -1 |
---|
| 1557 | */ |
---|
| 1558 | protected function init_poll_array($poll_id, $lang="") |
---|
| 1559 | { |
---|
| 1560 | $sql="SELECT ".$this->tables['polls'].".*, ".$this->tables['polls_lang'].".* |
---|
| 1561 | FROM ".$this->tables['polls']." INNER JOIN ".$this->tables['polls_lang']." |
---|
| 1562 | ON ".$this->tables['polls'].".id = ".$this->tables['polls_lang'].".id_poll |
---|
| 1563 | AND ".$this->tables['polls'].".id = '".$poll_id."' "; |
---|
| 1564 | if($lang=="") |
---|
| 1565 | { |
---|
| 1566 | $sql.=" AND ".$this->tables['polls'].".default_lang = ".$this->tables['polls_lang'].".lang "; |
---|
| 1567 | } |
---|
| 1568 | else |
---|
| 1569 | { |
---|
| 1570 | $sql.=" AND ".$this->tables['polls_lang'].".lang = '".$lang."' "; |
---|
| 1571 | } |
---|
| 1572 | $result=pwg_query($sql); |
---|
| 1573 | if($result) |
---|
| 1574 | { |
---|
| 1575 | return(mysql_fetch_array($result)); |
---|
| 1576 | } |
---|
| 1577 | return(false); |
---|
| 1578 | } |
---|
| 1579 | |
---|
| 1580 | /* |
---|
| 1581 | initialise an array from database to prepare form |
---|
| 1582 | input : poll_id, question_num |
---|
| 1583 | return an array if OK, else -1 |
---|
| 1584 | */ |
---|
| 1585 | protected function init_poll_question_array($poll_id, $question_num, $lang="") |
---|
| 1586 | { |
---|
| 1587 | $sql="SELECT ".$this->tables['polls_questions'].".*, |
---|
| 1588 | ".$this->tables['polls_questions_lang'].".*, |
---|
| 1589 | ".$this->tables['polls_answers_lang'].".* |
---|
| 1590 | FROM ".$this->tables['polls_questions']." INNER JOIN ".$this->tables['polls_questions_lang']." |
---|
| 1591 | ON ".$this->tables['polls_questions'].".id_poll = ".$this->tables['polls_questions_lang'].".id_poll |
---|
| 1592 | AND ".$this->tables['polls_questions'].".question_num = ".$this->tables['polls_questions_lang'].".id_question, |
---|
| 1593 | ".$this->tables['polls'].", |
---|
| 1594 | ".$this->tables['polls_answers_lang']." |
---|
| 1595 | WHERE ".$this->tables['polls'].".id = '".$poll_id."' |
---|
| 1596 | AND ".$this->tables['polls'].".id = ".$this->tables['polls_questions'].".id_poll |
---|
| 1597 | AND ".$this->tables['polls_answers_lang'].".id_poll = ".$this->tables['polls_questions'].".id_poll |
---|
| 1598 | AND ".$this->tables['polls_answers_lang'].".id_question = ".$this->tables['polls_questions'].".question_num |
---|
| 1599 | AND ".$this->tables['polls_answers_lang'].".lang = ".$this->tables['polls_questions_lang'].".lang |
---|
| 1600 | AND ".$this->tables['polls_questions'].".question_num = '".$question_num."' "; |
---|
| 1601 | if($lang=="") |
---|
| 1602 | { |
---|
| 1603 | $sql.=" AND ".$this->tables['polls'].".default_lang = ".$this->tables['polls_questions_lang'].".lang "; |
---|
| 1604 | } |
---|
| 1605 | else |
---|
| 1606 | { |
---|
| 1607 | $sql.=" AND ".$this->tables['polls_lang'].".lang = '".$lang."' "; |
---|
| 1608 | } |
---|
| 1609 | $sql.=" ORDER BY id_answer ASC "; |
---|
| 1610 | $result=pwg_query($sql); |
---|
| 1611 | if($result) |
---|
| 1612 | { |
---|
| 1613 | $returned=array(); |
---|
| 1614 | |
---|
| 1615 | $answnum=0; |
---|
| 1616 | while($row=mysql_fetch_array($result)) |
---|
| 1617 | { |
---|
| 1618 | if($answnum==0) |
---|
| 1619 | { |
---|
| 1620 | $returned['default_lang'] = $row['lang']; |
---|
| 1621 | $returned['question_type'] = $row['question_type']; |
---|
| 1622 | $returned['multi_max_answers'] = $row['multi_max_answers']; |
---|
| 1623 | $returned['description'] = $row['description']; |
---|
| 1624 | $returned['counter_answers'] = $row['counter_answers']; |
---|
| 1625 | } |
---|
| 1626 | $returned['answ'.$row['id_answer']] = $row['answer']; |
---|
| 1627 | $answnum++; |
---|
| 1628 | } |
---|
| 1629 | return($returned); |
---|
| 1630 | } |
---|
| 1631 | return(false); |
---|
| 1632 | } |
---|
| 1633 | |
---|
| 1634 | |
---|
| 1635 | /* |
---|
| 1636 | modify poll general info (no language needed) |
---|
| 1637 | input : an array of general values |
---|
| 1638 | return poll_id if OK, else -1 |
---|
| 1639 | */ |
---|
| 1640 | protected function modify_poll($poll_id, $values) |
---|
| 1641 | { |
---|
| 1642 | $sql="UPDATE ".$this->tables['polls']." |
---|
| 1643 | SET allowed_users = '".$values['allowed_users']."', |
---|
| 1644 | allowed_groups = '".$values['allowed_groups']."', |
---|
| 1645 | visible = '".$values['visible']."', |
---|
| 1646 | enabled = '".$values['enabled']."', |
---|
| 1647 | allow_comment = '".$values['allow_comment']."', |
---|
| 1648 | show_comments = '".$values['show_comments']."', |
---|
| 1649 | color_bars = '".$values['color_bars']."', |
---|
| 1650 | display_type = '".$values['display_type']."', |
---|
| 1651 | public_results = '".$values['public_results']."' |
---|
| 1652 | WHERE id = '".$poll_id."'"; |
---|
| 1653 | $result=pwg_query($sql); |
---|
| 1654 | if($result) |
---|
| 1655 | { |
---|
| 1656 | return($poll_id); |
---|
| 1657 | } |
---|
| 1658 | return(false); |
---|
| 1659 | } |
---|
| 1660 | |
---|
| 1661 | /* |
---|
| 1662 | modify poll general info (language needed) |
---|
| 1663 | input : an array of general values |
---|
| 1664 | return poll_id if OK, else -1 |
---|
| 1665 | */ |
---|
| 1666 | protected function modify_poll_lang($poll_id, $lang, $values) |
---|
| 1667 | { |
---|
| 1668 | $sql="UPDATE ".$this->tables['polls_lang']." |
---|
| 1669 | SET title = '".$values['title']."', |
---|
| 1670 | description = '".$values['description']."', |
---|
| 1671 | after_vote_text = '".$values['after_vote_text']."' |
---|
| 1672 | WHERE id_poll = '".$poll_id."' |
---|
| 1673 | AND lang = '".$lang."'"; |
---|
| 1674 | $result=pwg_query($sql); |
---|
| 1675 | if($result) |
---|
| 1676 | { |
---|
| 1677 | return($poll_id); |
---|
| 1678 | } |
---|
| 1679 | return(false); |
---|
| 1680 | } |
---|
| 1681 | |
---|
| 1682 | /* |
---|
| 1683 | modify poll question info (no language needed) |
---|
| 1684 | input : an array of general values |
---|
| 1685 | return poll_id if OK, else -1 |
---|
| 1686 | */ |
---|
| 1687 | protected function modify_poll_questions($poll_id, $question_num, $values) |
---|
| 1688 | { |
---|
| 1689 | $sql="UPDATE ".$this->tables['polls_questions']." |
---|
| 1690 | SET question_type = '".$values['question_type']."', |
---|
| 1691 | multi_max_answers = '".$values['multi_max_answers']."' |
---|
| 1692 | WHERE id_poll = '".$poll_id."' |
---|
| 1693 | AND question_num = '".$question_num."' "; |
---|
| 1694 | $result=pwg_query($sql); |
---|
| 1695 | if($result) |
---|
| 1696 | { |
---|
| 1697 | return($poll_id); |
---|
| 1698 | } |
---|
| 1699 | return(false); |
---|
| 1700 | } |
---|
| 1701 | |
---|
| 1702 | /* |
---|
| 1703 | modify poll question info (language needed) |
---|
| 1704 | return poll_id if OK, else -1 |
---|
| 1705 | */ |
---|
| 1706 | protected function modify_poll_questions_lang($poll_id, $id_question, $lang, $values) |
---|
| 1707 | { |
---|
| 1708 | $sql="UPDATE ".$this->tables['polls_questions_lang']." |
---|
| 1709 | SET description = '".$values['description']."' |
---|
| 1710 | WHERE id_poll = '".$poll_id."' |
---|
| 1711 | AND id_question = '".$id_question."' |
---|
| 1712 | AND lang = '".$lang."' "; |
---|
| 1713 | $result=pwg_query($sql); |
---|
| 1714 | if(!$result) |
---|
| 1715 | { |
---|
| 1716 | return(false); |
---|
| 1717 | } |
---|
| 1718 | return($poll_id); |
---|
| 1719 | } |
---|
| 1720 | |
---|
| 1721 | /* |
---|
| 1722 | modify poll question info (language needed) |
---|
| 1723 | return poll_id if OK, else -1 |
---|
| 1724 | */ |
---|
| 1725 | protected function modify_poll_answers_lang($id_poll, $id_question, $id_answer, $lang, $values) |
---|
| 1726 | { |
---|
| 1727 | $sql="SELECT id_poll |
---|
| 1728 | FROM ".$this->tables['polls_answers_lang']." |
---|
| 1729 | WHERE id_poll = '".$id_poll."' |
---|
| 1730 | AND id_question = '".$id_question."' |
---|
| 1731 | AND id_answer = '".$id_answer."' |
---|
| 1732 | AND lang = '".$lang."' "; |
---|
| 1733 | $result=pwg_query($sql); |
---|
| 1734 | if(mysql_num_rows($result)==0) |
---|
| 1735 | { |
---|
| 1736 | $values=array( |
---|
| 1737 | 'id_poll' => $id_poll, |
---|
| 1738 | 'id_question' => $id_question, |
---|
| 1739 | 'id_answer' => $id_answer, |
---|
| 1740 | 'answer_num' => $id_answer, |
---|
| 1741 | 'lang' => $lang, |
---|
| 1742 | 'answer' => $values['answer'] |
---|
| 1743 | ); |
---|
| 1744 | if($this->create_poll_answers($values)) |
---|
| 1745 | { |
---|
| 1746 | if($this->create_poll_answers_lang($values)) |
---|
| 1747 | { |
---|
| 1748 | return($id_poll); |
---|
| 1749 | } |
---|
| 1750 | }; |
---|
| 1751 | return(false); |
---|
| 1752 | } |
---|
| 1753 | else |
---|
| 1754 | { |
---|
| 1755 | $sql="UPDATE ".$this->tables['polls_answers_lang']." |
---|
| 1756 | SET answer = '".$values['answer']."' |
---|
| 1757 | WHERE id_poll = '".$id_poll."' |
---|
| 1758 | AND id_question = '".$id_question."' |
---|
| 1759 | AND id_answer = '".$id_answer."' |
---|
| 1760 | AND lang = '".$lang."' "; |
---|
| 1761 | $result=pwg_query($sql); |
---|
| 1762 | if(!$result) |
---|
| 1763 | { |
---|
| 1764 | return(false); |
---|
| 1765 | } |
---|
| 1766 | return($id_poll); |
---|
| 1767 | } |
---|
| 1768 | } |
---|
| 1769 | |
---|
| 1770 | protected function delete_poll($id_poll) |
---|
| 1771 | { |
---|
| 1772 | $sql="DELETE FROM ".$this->tables['polls']." |
---|
| 1773 | WHERE id = '".$id_poll."' "; |
---|
| 1774 | $result=pwg_query($sql); |
---|
| 1775 | if($result) |
---|
| 1776 | { |
---|
| 1777 | return($id_poll); |
---|
| 1778 | } |
---|
| 1779 | return(false); |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | protected function delete_poll_lang($id_poll, $lang="") |
---|
| 1783 | { |
---|
| 1784 | $sql="DELETE FROM ".$this->tables['polls_lang']." |
---|
| 1785 | WHERE id_poll = '".$id_poll."' "; |
---|
| 1786 | if($lang!="") |
---|
| 1787 | { |
---|
| 1788 | $sql.=" AND lang = '".$lang."' "; |
---|
| 1789 | } |
---|
| 1790 | $result=pwg_query($sql); |
---|
| 1791 | if($result) |
---|
| 1792 | { |
---|
| 1793 | return($id_poll); |
---|
| 1794 | } |
---|
| 1795 | return(false); |
---|
| 1796 | } |
---|
| 1797 | |
---|
| 1798 | protected function delete_poll_questions($id_poll, $id_question="") |
---|
| 1799 | { |
---|
| 1800 | $sql="DELETE FROM ".$this->tables['polls_questions']." |
---|
| 1801 | WHERE id_poll = '".$id_poll."' "; |
---|
| 1802 | if($id_question!="") |
---|
| 1803 | { |
---|
| 1804 | $sql.=" AND question_num = '".$id_question."' "; |
---|
| 1805 | } |
---|
| 1806 | $result=pwg_query($sql); |
---|
| 1807 | if($result) |
---|
| 1808 | { |
---|
| 1809 | $sql="UPDATE ".$this->tables['polls']; |
---|
| 1810 | if($id_question=="") |
---|
| 1811 | { |
---|
| 1812 | $sql.=" SET nb_questions = 0 "; |
---|
| 1813 | } |
---|
| 1814 | else |
---|
| 1815 | { |
---|
| 1816 | $sql.=" SET nb_questions = nb_questions-1 "; |
---|
| 1817 | } |
---|
| 1818 | $sql.=" WHERE id = '".$id_poll."'"; |
---|
| 1819 | $result=pwg_query($sql); |
---|
| 1820 | if($result) |
---|
| 1821 | { |
---|
| 1822 | return($id_poll); |
---|
| 1823 | } |
---|
| 1824 | } |
---|
| 1825 | return(false); |
---|
| 1826 | } |
---|
| 1827 | |
---|
| 1828 | protected function delete_poll_questions_lang($id_poll, $id_question="", $lang="") |
---|
| 1829 | { |
---|
| 1830 | if($id_question=="") |
---|
| 1831 | { |
---|
| 1832 | $lang=""; |
---|
| 1833 | } |
---|
| 1834 | $sql="DELETE FROM ".$this->tables['polls_questions_lang']." |
---|
| 1835 | WHERE id_poll = '".$id_poll."' "; |
---|
| 1836 | if($id_question!="") |
---|
| 1837 | { |
---|
| 1838 | $sql.=" AND id_question = '".$id_question."' "; |
---|
| 1839 | } |
---|
| 1840 | if($lang!="") |
---|
| 1841 | { |
---|
| 1842 | $sql.=" AND lang = '".$lang."' "; |
---|
| 1843 | } |
---|
| 1844 | $result=pwg_query($sql); |
---|
| 1845 | if($result) |
---|
| 1846 | { |
---|
| 1847 | return($id_poll); |
---|
| 1848 | } |
---|
| 1849 | return(false); |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | |
---|
| 1853 | protected function delete_poll_answers($id_poll, $id_question="", $id_answer="") |
---|
| 1854 | { |
---|
| 1855 | if($id_question=="") |
---|
| 1856 | { |
---|
| 1857 | $id_answer=""; |
---|
| 1858 | } |
---|
| 1859 | $sql="DELETE FROM ".$this->tables['polls_answers']." |
---|
| 1860 | WHERE id_poll = '".$id_poll."' "; |
---|
| 1861 | if($id_question!="") |
---|
| 1862 | { |
---|
| 1863 | $sql.=" AND id_question = '".$id_question."' "; |
---|
| 1864 | } |
---|
| 1865 | if($id_answer!="") |
---|
| 1866 | { |
---|
| 1867 | $sql.=" AND answer_num = '".$id_answer."' "; |
---|
| 1868 | } |
---|
| 1869 | |
---|
| 1870 | $result=pwg_query($sql); |
---|
| 1871 | if($result) |
---|
| 1872 | { |
---|
| 1873 | return($id_poll); |
---|
| 1874 | } |
---|
| 1875 | return(false); |
---|
| 1876 | } |
---|
| 1877 | |
---|
| 1878 | protected function delete_poll_answers_lang($id_poll, $id_question="", $id_answer="", $lang="") |
---|
| 1879 | { |
---|
| 1880 | if($id_question=="") |
---|
| 1881 | { |
---|
| 1882 | $id_answer=""; |
---|
| 1883 | } |
---|
| 1884 | if($id_answer=="") |
---|
| 1885 | { |
---|
| 1886 | $lang=""; |
---|
| 1887 | } |
---|
| 1888 | $sql="DELETE FROM ".$this->tables['polls_answers_lang']." |
---|
| 1889 | WHERE id_poll = '".$id_poll."' "; |
---|
| 1890 | if($id_question!="") |
---|
| 1891 | { |
---|
| 1892 | $sql.=" AND id_question = '".$id_question."' "; |
---|
| 1893 | } |
---|
| 1894 | if($id_answer!="") |
---|
| 1895 | { |
---|
| 1896 | $sql.=" AND id_answer = '".$id_answer."' "; |
---|
| 1897 | } |
---|
| 1898 | if($lang!="") |
---|
| 1899 | { |
---|
| 1900 | $sql.=" AND lang = '".$lang."' "; |
---|
| 1901 | } |
---|
| 1902 | $result=pwg_query($sql); |
---|
| 1903 | if($result) |
---|
| 1904 | { |
---|
| 1905 | return($id_poll); |
---|
| 1906 | } |
---|
| 1907 | return(false); |
---|
| 1908 | } |
---|
| 1909 | |
---|
| 1910 | |
---|
| 1911 | /* |
---|
| 1912 | return a list of user/ip making a vote on the poll |
---|
| 1913 | list is paged with $my_config['mypolls_nbuser_per_page'] value |
---|
| 1914 | |
---|
| 1915 | an array is returned : |
---|
| 1916 | array[0] : list |
---|
| 1917 | array[1] : total number of pages |
---|
| 1918 | */ |
---|
| 1919 | protected function get_poll_users_vote($poll_id, $num_page=1) |
---|
| 1920 | { |
---|
| 1921 | $returned=array(array(), -1); |
---|
| 1922 | $sql="SELECT SQL_CALC_FOUND_ROWS IF(username IS NULL, user_id, CONCAT(' ',username)) AS name |
---|
| 1923 | FROM ".$this->tables['polls_votes']." LEFT JOIN ".USERS_TABLE." |
---|
| 1924 | ON ".$this->tables['polls_votes'].".user_id = ".USERS_TABLE.".id |
---|
| 1925 | WHERE poll_id = '".$poll_id."' |
---|
| 1926 | ORDER BY name |
---|
| 1927 | LIMIT ".(($num_page-1)*$this->my_config['mypolls_nbuser_per_page']).", ".$this->my_config['mypolls_nbuser_per_page']; |
---|
| 1928 | |
---|
| 1929 | $result = pwg_query($sql); |
---|
| 1930 | if($result) |
---|
| 1931 | { |
---|
| 1932 | while($row = mysql_fetch_row($result)) |
---|
| 1933 | { array_push($returned[0], $row[0]); } |
---|
| 1934 | |
---|
| 1935 | //compute number of pages |
---|
| 1936 | $sql="select FOUND_ROWS()"; |
---|
| 1937 | $result=pwg_query($sql); |
---|
| 1938 | if($result) |
---|
| 1939 | { $row = mysql_fetch_row($result); $returned[1] = ceil($row[0]/$this->my_config['mypolls_nbuser_per_page']); } |
---|
| 1940 | else |
---|
| 1941 | { $returned[1] = -1; } |
---|
| 1942 | } |
---|
| 1943 | return($returned); |
---|
| 1944 | } |
---|
| 1945 | |
---|
| 1946 | |
---|
| 1947 | /* --------------------------------------------------------------------------- |
---|
| 1948 | ajax functions |
---|
| 1949 | --------------------------------------------------------------------------- */ |
---|
| 1950 | |
---|
| 1951 | /* |
---|
| 1952 | return html formatted informations for a poll |
---|
| 1953 | (need by poll's list view) |
---|
| 1954 | */ |
---|
| 1955 | protected function ajax_poll_detail_list($poll_id) |
---|
| 1956 | { |
---|
| 1957 | $local_tpl = new Template(MYPOLLS_PATH."admin/", ""); |
---|
| 1958 | $local_tpl->set_filename('body_page', |
---|
| 1959 | dirname($this->filelocation).'/admin/plugin_admin_detail.tpl'); |
---|
| 1960 | |
---|
| 1961 | $languages=get_languages(); |
---|
| 1962 | $poll_values=$this->get_poll_values($poll_id); |
---|
| 1963 | $poll_langs=$this->get_poll_languages($poll_id); |
---|
| 1964 | |
---|
| 1965 | $langs="<b>".$languages[$poll_values['default_lang']]."</b>"; |
---|
| 1966 | foreach($poll_langs as $key => $val) |
---|
| 1967 | { |
---|
| 1968 | if($val!=$poll_values['default_lang']) |
---|
| 1969 | { |
---|
| 1970 | $langs.=", ".$languages[$val]; |
---|
| 1971 | } |
---|
| 1972 | } |
---|
| 1973 | |
---|
| 1974 | $local_tpl->assign('datas', |
---|
| 1975 | array( |
---|
| 1976 | 'MYPOLLS_ATT_VISIT_WO_VOTE' => $poll_values['visit_without_vote'], |
---|
| 1977 | 'MYPOLLS_ATT_VISIT_A_VOTE' => $poll_values['visit_after_vote'], |
---|
| 1978 | 'MYPOLLS_NB_COMMENTS' => ($poll_values['allow_comment']=='y')?"(".$poll_values['nb_comments'].")":"", |
---|
| 1979 | 'MYPOLLS_ATT_ALLOW_COMMENT' => l10n('mypolls_yesno_'.$poll_values['allow_comment']), |
---|
| 1980 | 'MYPOLLS_ATT_SHOW_COMMENTS' => l10n('mypolls_yesno_'.$poll_values['show_comments']), |
---|
| 1981 | 'MYPOLLS_ATT_DISPLAY_TYPE' => l10n('mypolls_display_'.$poll_values['display_type']), |
---|
| 1982 | 'MYPOLLS_POLL_LANGS' => $langs, |
---|
| 1983 | 'MYPOLLS_ATT_PUBLIC_RESULTS' => l10n('mypolls_yesno_'.$poll_values['public_results']) |
---|
| 1984 | ) |
---|
| 1985 | ); |
---|
| 1986 | |
---|
| 1987 | return($local_tpl->parse('body_page', true)); |
---|
| 1988 | } |
---|
| 1989 | |
---|
| 1990 | /* |
---|
| 1991 | return html formatted informations about poll's voting users |
---|
| 1992 | */ |
---|
| 1993 | protected function ajax_poll_user_list($poll_id) |
---|
| 1994 | { |
---|
| 1995 | if(!isset($_REQUEST['vpage'])) |
---|
| 1996 | { |
---|
| 1997 | $page=1; |
---|
| 1998 | } |
---|
| 1999 | else |
---|
| 2000 | { |
---|
| 2001 | $page=$_REQUEST['vpage']; |
---|
| 2002 | } |
---|
| 2003 | |
---|
| 2004 | $voter_list=$this->get_poll_users_vote($poll_id, $page); |
---|
| 2005 | |
---|
| 2006 | $local_tpl = new Template(MYPOLLS_PATH."admin/", ""); |
---|
| 2007 | $local_tpl->set_filename('body_page', |
---|
| 2008 | dirname($this->filelocation).'/admin/plugin_admin_voter_list.tpl'); |
---|
| 2009 | |
---|
| 2010 | //users list |
---|
| 2011 | $voter_list_rows=array(); |
---|
| 2012 | foreach($voter_list[0] as $key => $val) |
---|
| 2013 | { |
---|
| 2014 | $voter_list_rows[]=array('USERNAME' => $val); |
---|
| 2015 | } |
---|
| 2016 | |
---|
| 2017 | //make pages links |
---|
| 2018 | if($voter_list[1]>1) |
---|
| 2019 | { |
---|
| 2020 | $plural="s"; |
---|
| 2021 | } |
---|
| 2022 | else |
---|
| 2023 | { |
---|
| 2024 | $plural=""; |
---|
| 2025 | } |
---|
| 2026 | $pages_links=l10n("mypolls_page".$plural."_label")." : "; |
---|
| 2027 | |
---|
| 2028 | if($voter_list[1]<=0) |
---|
| 2029 | { |
---|
| 2030 | $pages_links=""; |
---|
| 2031 | } |
---|
| 2032 | else |
---|
| 2033 | { |
---|
| 2034 | for($i=1;$i<=$voter_list[1];$i++) |
---|
| 2035 | { |
---|
| 2036 | if($i==$page) |
---|
| 2037 | { $pages_links.=" $i "; } |
---|
| 2038 | else |
---|
| 2039 | { |
---|
| 2040 | $pages_links.="<a style='cursor:pointer;' onclick='load_poll_voter_list($i);'> $i </a>"; |
---|
| 2041 | } |
---|
| 2042 | } |
---|
| 2043 | } |
---|
| 2044 | |
---|
| 2045 | |
---|
| 2046 | $local_tpl->assign("datas", array('PAGES' => $pages_links)); |
---|
| 2047 | $local_tpl->assign("voter_list_rows", $voter_list_rows); |
---|
| 2048 | |
---|
| 2049 | return($local_tpl->parse('body_page', true)); |
---|
| 2050 | } |
---|
| 2051 | |
---|
| 2052 | |
---|
| 2053 | /* |
---|
| 2054 | delete a comment |
---|
| 2055 | */ |
---|
| 2056 | protected function ajax_poll_delete_comment($poll_id) |
---|
| 2057 | { |
---|
| 2058 | if(!isset($_REQUEST['comment_id'])) |
---|
| 2059 | { |
---|
| 2060 | return("<div class='errors'>".l10n("mypolls_no_comment_to_delete")."<br> </div>"); |
---|
| 2061 | } |
---|
| 2062 | |
---|
| 2063 | if((!is_admin()) || (is_adviser())) |
---|
| 2064 | { |
---|
| 2065 | $returned="<div class='errors'>".l10n("mypolls_adviser_not_allowed")."<br> </div>"; |
---|
| 2066 | } |
---|
| 2067 | else |
---|
| 2068 | { |
---|
| 2069 | $sql="UPDATE ".$this->tables['polls_votes']." |
---|
| 2070 | SET user_comment = '' |
---|
| 2071 | WHERE poll_id = '".$poll_id."' |
---|
| 2072 | AND user_id = '".$_REQUEST['comment_id']."' "; |
---|
| 2073 | $result=pwg_query($sql); |
---|
| 2074 | if(!$result) |
---|
| 2075 | { |
---|
| 2076 | $returned="<div class='errors'>".l10n("mypolls_errors_deleting_comment")."<br> </div>"; |
---|
| 2077 | } |
---|
| 2078 | else |
---|
| 2079 | { |
---|
| 2080 | $returned="<div class='infos'>".l10n("mypolls_infos_deleted_comment")."<br> </div>"; |
---|
| 2081 | } |
---|
| 2082 | } |
---|
| 2083 | $returned.=$this->ajax_poll_comment_list($poll_id); |
---|
| 2084 | return($returned); |
---|
| 2085 | } |
---|
| 2086 | |
---|
| 2087 | |
---|
| 2088 | |
---|
| 2089 | |
---|
| 2090 | } //class |
---|
| 2091 | |
---|
| 2092 | ?> |
---|