Changeset 32457 for extensions/ConcoursPhoto/include
- Timestamp:
- Feb 12, 2021, 7:00:27 PM (4 years ago)
- Location:
- extensions/ConcoursPhoto/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/ConcoursPhoto/include/Concours.class.php
r9370 r32457 12 12 var $concours_infos = array(); 13 13 14 /* var $create_date = null;15 var $name = null;16 var $descr = null;17 var $begin_date = null;18 var $end_date = null;19 var $category = null;20 var $groups = null;21 */22 23 14 // General configuration parameters 24 15 var $my_config = array(); 25 /*26 active_menubar27 nbconcours_menubar28 */29 16 var $user_groups = array(); 30 17 var $debug = false; 31 32 // Class constructor with concours id. Return NULL if not existing or create it 33 function Concours($concours_id = null, $force_creation = NULL) 34 { 35 // $this->get_user_groups(); 18 19 20 /** 21 * Class constructor with concours id. 22 * Return NULL if not existing or create it 23 */ 24 function __construct($concours_id = null, $force_creation = NULL) 25 { 36 26 if ($concours_id !== null) 37 27 { … … 44 34 45 35 46 // Load general configuration from config_database 47 function load_config() 48 { 49 50 $query = ' 51 SELECT value 52 FROM '.CONFIG_TABLE.' 53 WHERE param = \'concoursphoto\' 54 ;'; 55 36 /** 37 * Load configuration from database 38 * Assign value to the variable $config 39 */ 40 function load_config() { 41 $query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="concoursphoto";'; 56 42 $result = pwg_query($query); 57 43 58 if($result) 59 { 60 $row = mysql_fetch_row($result); 61 if(is_string($row[0])) 62 { 63 $this->my_config = unserialize(($row[0])); 64 } 44 if(isset($result)) { 45 $row = pwg_db_fetch_row($result); 46 if(is_string($row[0])) { 47 $this->my_config = unserialize(($row[0])); 48 } 65 49 } 66 $this->load_default_config(); 67 } 68 69 // Initialize default values of params 50 if ($this->debug) 51 foreach ($this->my_config as $key => $value) 52 { 53 echo "my_config[".$key."] = ".$value."\n"; 54 } 55 $this->load_default_config(); 56 } 57 58 59 /** 60 * Load default configuration, initialize default values of params 61 */ 70 62 private function load_default_config() 71 63 { … … 96 88 } 97 89 90 /** 91 * Save the current configuration (ie the value of $config) to the database 92 */ 93 function set_config() { 94 conf_update_param('concoursphoto', pwg_db_real_escape_string(serialize($this->my_config))); 95 } 96 98 97 99 98 // Retrieve user groups … … 101 100 { 102 101 global $user; 103 if ($this->debug)104 foreach ($user as $id=>$val)105 {106 if (is_array($val))107 foreach ($val as $id2=>$val2)108 echo "user[".$id."][".$id2."]=".$val2."\n";109 else110 echo "user[".$id."]=".$val."\n";111 }112 113 102 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; 114 if ($this->debug) echo $query."\n"; 103 115 104 $result = pwg_query($query); 116 while ($row = mysql_fetch_assoc($result))105 while ($row = pwg_db_fetch_array($result)) 117 106 { 118 107 array_push($this->user_groups, $row['group_id']); 119 108 } 120 121 if ($this->debug)122 foreach ($this->user_groups as $gr)123 echo "Group=".$gr."\n";124 109 125 110 } … … 144 129 $result = pwg_query($query); 145 130 if ($result) 146 $this->concours_infos = mysql_fetch_assoc($result); 147 } 148 149 } 131 $this->concours_infos = pwg_db_fetch_array($result); 132 } 133 134 } 135 150 136 151 137 // save informations on database for a concours_id … … 165 151 `groups`, 166 152 `method`, 167 `guest` 153 `guest`, 154 `admin` 168 155 169 156 ) … … 172 159 \"".$this->concours_infos['begin_date']."\", \"".$this->concours_infos['end_date']."\", 173 160 ".$this->concours_infos['category'].", ".$this->concours_infos['groups'].", 174 ".$this->concours_infos['method'].", ".($this->concours_infos['guest'] ? "TRUE" : "FALSE")." 161 ".$this->concours_infos['method'].", ".($this->concours_infos['guest'] ? "TRUE" : "FALSE").", 162 ".($this->concours_infos['admin'] ? "TRUE" : "FALSE")." 175 163 );"; 176 164 if (pwg_query($query) != null) … … 199 187 groups = ".$this->concours_infos['groups'].", 200 188 method = ".$this->concours_infos['method'].", 201 guest = ".($this->concours_infos['guest'] ? "TRUE" : "FALSE")." 189 guest = ".($this->concours_infos['guest'] ? "TRUE" : "FALSE").", 190 admin = ".($this->concours_infos['admin'] ? "TRUE" : "FALSE")." 202 191 203 192 WHERE id = ".($concours_id !== NULL ? $concours_id : $this->concours_id)." … … 245 234 $query = ' 246 235 DELETE 247 FROM ' . CONCOURS_TABLE .' 248 WHERE id =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 236 FROM ' . CONCOURS_RESULT_TABLE .' 237 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 238 '; 239 pwg_query($query); 240 $query = ' 241 DELETE 242 FROM ' . CONCOURS_DATA_TABLE .' 243 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 249 244 '; 250 245 pwg_query($query); … … 257 252 $query = ' 258 253 DELETE 259 FROM ' . CONCOURS_ DATA_TABLE .'260 WHERE id _concours=' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '254 FROM ' . CONCOURS_TABLE .' 255 WHERE id =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 261 256 '; 262 257 pwg_query($query); 263 $query = '264 DELETE265 FROM ' . CONCOURS_RESULT_TABLE .'266 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '267 ';268 pwg_query($query);269 258 } 270 259 else 271 260 return false; 272 261 262 } 263 264 265 // delete all closed concours from db 266 function delete_allclosed_concours() 267 { 268 $concours_list=array(); 269 $query = ' 270 SELECT id 271 FROM ' . CONCOURS_TABLE .' 272 WHERE time_to_sec(TIMEDIFF(now(), end_date)) > 0 273 AND id>0;'; 274 275 $result = pwg_query($query); 276 while ($row = pwg_db_fetch_assoc($result)) 277 { 278 $this->delete_concours($row['id']); 279 } 273 280 } 274 281 … … 288 295 289 296 $result = pwg_query($query); 290 if ($this->debug) echo $query."\n";291 297 if ($result != NULL) 292 298 return true; … … 311 317 312 318 $result = pwg_query($query); 313 if ($this->debug) echo $query."\n";314 319 if ($result != NULL) 315 320 return true; … … 321 326 } 322 327 323 328 // Get high value of concours (max score for each criterias) 329 function get_MaxScore_concours($concours_id = null) 330 { 331 $max = 0; 332 $query = ' 333 SELECT criteria_id, max_value, ponderation, uppercriteria 334 FROM ' . CONCOURS_DETAIL_TABLE .' 335 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 336 ORDER BY criteria_id 337 '; 338 $result = pwg_query($query); 339 while ($row = pwg_db_fetch_array($result)) 340 { 341 if ($row['uppercriteria'] != NULL || !$this->is_criterias_contains_sub($row['criteria_id'])) // subcriteria or uppercriteria without sub 342 $max += $row['max_value']*$row['ponderation']; 343 } 344 return $max; 345 346 347 } 348 324 349 // Get criterias that are stored on db for default mode (concours_id = 0) 325 350 function get_default_criterias() … … 328 353 $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id 329 354 FROM ' . CONCOURS_DETAIL_TABLE . ' ;'; 330 list($next_element_id) = mysql_fetch_array(pwg_query($query));355 list($next_element_id) = pwg_db_fetch_array(pwg_query($query)); 331 356 332 357 foreach ($criterias as $criteria) 333 358 { 334 if ($this->debug) echo "NEXT =".$next_element_id."\n"; 359 335 360 $query = 'INSERT INTO '.CONCOURS_DETAIL_TABLE.' 336 361 (id, id_concours, criteria_id, name, descr, min_value, max_value, ponderation, uppercriteria)' … … 343 368 344 369 $result = pwg_query($query); 345 if ($this->debug) echo $query; 370 346 371 $next_element_id = $next_element_id +1; 347 372 } … … 361 386 '; 362 387 $result = pwg_query($query); 363 if ($this->debug) echo $query."\n"; 364 while ($row = mysql_fetch_assoc($result)) 388 while ($row = pwg_db_fetch_array($result)) 365 389 { 366 390 array_push($criteria_list, $row); … … 386 410 '; 387 411 $result = pwg_query($query); 388 if ($this->debug) echo $query."\n"; 389 while ($row = mysql_fetch_assoc($result)) 390 { 391 if ($this->debug) echo "criteria_id=".$row['criteria_id']."\n"; 412 413 while ($row = pwg_db_fetch_array($result)) 392 414 array_push($criteria_list, $row); 393 }394 415 return $criteria_list; 395 416 } … … 410 431 '; 411 432 $result = pwg_query($query); 412 if ($this->debug) echo $query."\n"; 413 // mini 1 line 414 if(mysql_fetch_assoc($result)) 433 if(pwg_db_fetch_array($result)) 415 434 return true; 416 435 else … … 435 454 '; 436 455 $result = pwg_query($query); 437 if ($this->debug) echo $query."\n"; 438 while ($row = mysql_fetch_assoc($result)) 456 while ($row = pwg_db_fetch_array($result)) 439 457 { 440 458 array_push($criteria_list, $row); … … 460 478 '; 461 479 $result = pwg_query($query); 462 if ($this->debug) echo $query."\n"; 463 $criteria = mysql_fetch_assoc($result); 464 /* while ($row = mysql_fetch_assoc($result)) 465 { 466 array_push($criteria, $row); 467 } 468 */ 480 481 $criteria = pwg_db_fetch_array($result); 469 482 } 470 483 return $criteria; … … 483 496 '; 484 497 $result = pwg_query($query); 485 if ($this->debug) echo $query."\n"; 486 $criteria = mysql_fetch_assoc($result); 487 /* while ($row = mysql_fetch_assoc($result)) 488 { 489 array_push($criteria, $row); 490 } 491 */ 492 return $criteria; 498 499 $criteria = pwg_db_fetch_array($result); 500 return $criteria; 493 501 494 502 } … … 504 512 $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id 505 513 FROM ' . CONCOURS_DETAIL_TABLE . ' ;'; 506 list($next_element_id) = mysql_fetch_array(pwg_query($query)); 514 list($next_element_id) = pwg_db_fetch_array(pwg_query($query)); 515 507 516 $query = 'SELECT IF(MAX(criteria_id)+1 IS NULL, 1, MAX(criteria_id)+1) AS next_criteria_id 508 517 FROM ' . CONCOURS_DETAIL_TABLE . ' 509 518 WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ) . ' ;'; 510 list($next_criteria_id) = mysql_fetch_array(pwg_query($query));519 list($next_criteria_id) = pwg_db_fetch_array(pwg_query($query)); 511 520 512 521 $query = ' … … 553 562 554 563 pwg_query($query); 555 556 if ($this->debug) echo $query."\n";557 558 564 } 559 565 } … … 573 579 '; 574 580 $result = pwg_query($query); 575 if ($this->debug) echo $query."\n";581 576 582 if($result) 577 583 return true; … … 594 600 '; 595 601 $result = pwg_query($query); 596 if ($this->debug) echo $query."\n";597 602 598 603 } … … 608 613 $result = pwg_query($query); 609 614 // For each images 610 if ( mysql_fetch_assoc($result))615 if (pwg_db_fetch_array($result)) 611 616 return true; 612 617 else … … 614 619 615 620 } 621 622 623 616 624 617 625 // function to return the number of votes for a concours by images … … 628 636 $result = pwg_query($query); 629 637 $nbvotes = array(); 630 while ($row = mysql_fetch_assoc($result))638 while ($row = pwg_db_fetch_array($result)) 631 639 { 632 640 $nbvotes[$row['img_id']] = $row['NBVOTE']; … … 634 642 635 643 // Add guest infos 636 $query = 'SELECT img_id, COUNT(DISTINCT user_id,ipguest) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE644 $query = 'SELECT img_id, COUNT(DISTINCT ipguest) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE 637 645 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ) 638 646 .' AND ipguest IS NOT NULL' … … 641 649 642 650 $result = pwg_query($query); 643 if ($this->debug) echo "NBVOTE = ".$query."\n";644 while ($row = mysql_fetch_assoc($result)) 651 while ($row = pwg_db_fetch_array($result)) 652 645 653 if (!isset($nbvotes[$row['img_id']])) 646 654 $nbvotes[$row['img_id']] = $row['NBVOTE']; 647 655 else 648 656 $nbvotes[$row['img_id']] += $row['NBVOTE']; 649 657 650 658 return $nbvotes; 651 659 } 652 660 661 662 663 // Get All user that are vote for guest who have vote (IP Stores in db) in a concours 664 function get_user_list($concours_id = NULL) 665 { 666 global $conf; 667 $userid = array(); 668 if ($concours_id!== null or $this->concours_id !== null) 669 { 670 $query = ' 671 SELECT distinct(user_id) 672 FROM ' . CONCOURS_DATA_TABLE .' 673 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 674 AND ipguest IS NULL 675 AND user_id !='.$conf['guest_id'] 676 677 .' ORDER BY user_id 678 '; 679 $result = pwg_query($query); 680 while ($row = pwg_db_fetch_array($result)) 681 { 682 array_push($userid, $row['user_id']); 683 } 684 } 685 return $userid; 686 } 687 688 653 689 // Get All iaddr for guest who have vote (IP Stores in db) in a concours 654 690 function get_guest_list($concours_id = NULL) 655 691 { 692 global $conf; 656 693 $ipguest = array(); 657 694 if ($concours_id!== null or $this->concours_id !== null) … … 660 697 SELECT distinct(ipguest) 661 698 FROM ' . CONCOURS_DATA_TABLE .' 662 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . ' 663 AND ipguest IS NOT NULL 699 WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) 700 .' AND user_id = '.$conf['guest_id'] 701 .' AND ipguest IS NOT NULL 664 702 ORDER BY ipguest 665 703 '; 666 704 $result = pwg_query($query); 667 if ($this->debug) echo $query."\n"; 668 while ($row = mysql_fetch_assoc($result)) 705 while ($row = pwg_db_fetch_array($result)) 669 706 { 670 707 array_push($ipguest, $row['ipguest']); … … 689 726 // var which contains id=img_id and val =global note 690 727 $global_note = array(); 728 // FOR MODERATION 729 // var which contains id=user_id and val =global note 730 $vote_by_user = array(); 731 $amplitiudeMINmax = 999; // MIN of all max score (for each users) 732 $amplitiudeMAXmin = -999; // MIN of all max score (for each users) 733 $REFaverage = 0; // reference average (average between amplitiudeMINmax and amplitiudeMAXmin) 734 $global_note_mod1 = array(); 735 $global_note_mod2 = array(); 736 691 737 if ($concours_id!== null or $this->concours_id !== null) 692 738 { … … 698 744 $nbvotes = $this->nb_votes_by_img($concours_id); 699 745 746 700 747 $user_id = array(); 701 748 // vars not initialized … … 703 750 $this->get_concours(); 704 751 $category = $this->concours_infos['category']; 705 706 if ($this->debug) 707 echo "CAT=".$category; 752 708 753 // Get all user_id from a concours 709 754 $query = 'SELECT DISTINCT user_id' … … 713 758 .';'; 714 759 $result = pwg_query($query); 715 if ($this->debug) 716 echo $query; 717 while ($row = mysql_fetch_assoc($result)) 760 761 while ($row = pwg_db_fetch_array($result)) 718 762 array_push($user_id, $row['user_id']); 719 763 720 764 // Add guest info is present 721 765 $ipguest = array(); 722 if ($concours_id!== null) 766 if ($concours_id!== null or $this->concours_id !== null) 767 { 768 if ($this->debug) 769 echo "Check IPGUEST"; 723 770 $ipguest = $this->get_guest_list(($concours_id !== null ? $concours_id : $this->concours_id )); 724 725 if ($this->debug) 726 { 727 foreach ($user_id as $userid) 728 echo "USER = ".$userid; 729 foreach ($ipguest as $userid) 730 echo "IPGUEST = ".$userid; 731 } 771 } 772 732 773 733 774 // recover all img_id from the category … … 736 777 .' WHERE category_id = '.$category.';'; 737 778 779 $nb_image_concours = 0; 738 780 $result = pwg_query($query); 739 781 // For each images 740 while ($row = mysql_fetch_assoc($result))782 while ($row = pwg_db_fetch_array($result)) 741 783 { 742 if ($this->debug) echo "IMG_ID=".$row['image_id']."\n"; 784 $nb_image_concours++; 785 743 786 foreach ($user_id as $i => $userid) 744 787 { 788 $img_note_user = $this->get_img_globalnote_user($row['image_id'], null, $userid); 789 745 790 if (!isset($global_note[$row['image_id']])) 746 791 $global_note[$row['image_id']] = 0; 747 $global_note[$row['image_id']] += $this->get_img_globalnote_user($row['image_id'], null, $userid); 792 // FOR MODERATION 793 // store the nb of vote for each user 794 if ($img_note_user >= 0) // user has made a vote 795 { 796 if (!isset($vote_by_user[$userid]['nbvote'])) 797 $vote_by_user[$userid]['nbvote'] = 0; 798 799 $vote_by_user[$userid]['nbvote'] ++; // update vote counter 800 801 $global_note[$row['image_id']] += $img_note_user ; 802 803 804 // FOR MODERATION 805 // store the total of note for the same user 806 if (!isset($vote_by_user[$userid]['totalvote'])) 807 $vote_by_user[$userid]['totalvote'] = 0; 808 $vote_by_user[$userid]['totalvote'] += $img_note_user; 809 // FOR MODERATION 810 // store min/max for each user 811 if (!isset($vote_by_user[$userid]['min'])) $vote_by_user[$userid]['min'] = 999; 812 if (!isset($vote_by_user[$userid]['max'])) $vote_by_user[$userid]['max'] = 0; 813 814 815 if ($vote_by_user[$userid]['min'] > $img_note_user) $vote_by_user[$userid]['min'] = $img_note_user; 816 if ($vote_by_user[$userid]['max'] < $img_note_user) $vote_by_user[$userid]['max'] = $img_note_user; 817 } 818 748 819 } 749 820 // Add guest scores if present 750 foreach ($ipguest as $i => $ ipguestt)821 foreach ($ipguest as $i => $userid) 751 822 { 823 824 $img_note_user = $this->get_img_globalnote_user($row['image_id'], null, null, $userid); // $userid contains the ip address for the guest! 752 825 if (!isset($global_note[$row['image_id']])) 753 826 $global_note[$row['image_id']] = 0; 754 $global_note[$row['image_id']] += $this->get_img_globalnote_user($row['image_id'], null, null, $ipguestt); 827 828 // FOR MODERATION 829 // store the nb of vote for each guest (with ipaddr) 830 if ($img_note_user >= 0) // user has made a vote 831 { 832 if (!isset($vote_by_user[$userid]['nbvote'])) 833 $vote_by_user[$userid]['nbvote'] = 0; 834 835 $vote_by_user[$userid]['nbvote'] ++; // update vote counter 836 837 $global_note[$row['image_id']] += $img_note_user ; 838 839 840 // FOR MODERATION 841 // store the total of note for the same user 842 if (!isset($vote_by_user[$userid]['totalvote'])) 843 $vote_by_user[$userid]['totalvote'] = 0; 844 $vote_by_user[$userid]['totalvote'] += $img_note_user; 845 // FOR MODERATION 846 // store min/max for each user 847 if (!isset($vote_by_user[$userid]['min'])) $vote_by_user[$userid]['min'] = 999; 848 if (!isset($vote_by_user[$userid]['max'])) $vote_by_user[$userid]['max'] = 0; 849 850 851 if ($vote_by_user[$userid]['min'] > $img_note_user) $vote_by_user[$userid]['min'] = $img_note_user; 852 if ($vote_by_user[$userid]['max'] < $img_note_user) $vote_by_user[$userid]['max'] = $img_note_user; 853 } 854 755 855 } 756 856 } 757 if ($this->debug) 857 858 // FOR MODERATION 859 // calcul the average by user and min/max global 860 foreach ($user_id as $i => $userid) 758 861 { 759 foreach ($global_note as $id => $val) 760 echo "Note img ( ".$id.") = ".$val."\n"; 862 $vote_by_user[$userid]['average'] = $vote_by_user[$userid]['totalvote']/$vote_by_user[$userid]['nbvote']; 863 $vote_by_user[$userid]['lowerAmp'] = $vote_by_user[$userid]['min']; 864 // calcul the max value of the concours (for the moderation) 865 $vote_by_user[$userid]['upperAmp'] = $this->get_MaxScore_concours() - $vote_by_user[$userid]['max']; 866 867 $vote_by_user[$userid]['minLevel'] = $vote_by_user[$userid]['average'] - $vote_by_user[$userid]['lowerAmp']; 868 $vote_by_user[$userid]['maxLevel'] = $vote_by_user[$userid]['average'] + $vote_by_user[$userid]['upperAmp']; 869 if ($amplitiudeMINmax > $vote_by_user[$userid]['maxLevel']) $amplitiudeMINmax = $vote_by_user[$userid]['maxLevel']; 870 if ($amplitiudeMAXmin < $vote_by_user[$userid]['minLevel']) $amplitiudeMAXmin = $vote_by_user[$userid]['minLevel']; 761 871 } 872 873 // calcul the average by guest and min/max global 874 foreach ($ipguest as $i => $userid) 875 { 876 $vote_by_user[$userid]['average'] = $vote_by_user[$userid]['totalvote']/$vote_by_user[$userid]['nbvote']; 877 $vote_by_user[$userid]['lowerAmp'] = $vote_by_user[$userid]['min']; 878 // calcul the max value of the concours (for the moderation) 879 $vote_by_user[$userid]['upperAmp'] = $this->get_MaxScore_concours() - $vote_by_user[$userid]['max']; 880 881 $vote_by_user[$userid]['minLevel'] = $vote_by_user[$userid]['average'] - $vote_by_user[$userid]['lowerAmp']; 882 $vote_by_user[$userid]['maxLevel'] = $vote_by_user[$userid]['average'] + $vote_by_user[$userid]['upperAmp']; 883 if ($amplitiudeMINmax > $vote_by_user[$userid]['maxLevel']) $amplitiudeMINmax = $vote_by_user[$userid]['maxLevel']; 884 if ($amplitiudeMAXmin < $vote_by_user[$userid]['minLevel']) $amplitiudeMAXmin = $vote_by_user[$userid]['minLevel']; 885 886 } 887 888 889 // FOR MODERATION 890 // calcul the reference average 891 $calcultemp = (int)($amplitiudeMINmax+$amplitiudeMAXmin)/2+0.5; 892 if ((int)(($amplitiudeMINmax+$amplitiudeMAXmin)/2+0.5) > $amplitiudeMAXmin) 893 { 894 if ((int)(($amplitiudeMINmax+$amplitiudeMAXmin)/2+0.5) < $amplitiudeMINmax) 895 $REFaverage = (int)(($amplitiudeMINmax+$amplitiudeMAXmin)/2+0.5); 896 else 897 $REFaverage = $amplitiudeMINmax; 898 } 899 else 900 $REFaverage = $amplitiudeMAXmin; 901 902 903 // FOR MODERATION 904 // calcul the moderation scopr for each users 905 foreach ($user_id as $i => $userid) 906 $vote_by_user[$userid]['moderation'] = $REFaverage - $vote_by_user[$userid]['average']; 907 908 // FOR MODERATION 909 // calcul the moderation scopr for each guest ($ipguest) 910 foreach ($ipguest as $i => $userid) 911 $vote_by_user[$userid]['moderation'] = $REFaverage - $vote_by_user[$userid]['average']; 912 913 // FOR MODERATION 914 // need to parse again image for new calcul with moderation 915 // moderation 1 => For each photo without note (user = author or user != author but no vote) add each user avaerage to the total of note and calcul the average 916 // moderation 2 => For each photo with note, adapt/change all the value with the moderation value : user note + moderation. 917 918 // parse again all img_id from the category 919 $query = 'SELECT DISTINCT(image_id)' 920 .' FROM ' .IMAGE_CATEGORY_TABLE 921 .' WHERE category_id = '.$category.';'; 922 923 $result = pwg_query($query); 924 // For each images 925 while ($row = pwg_db_fetch_array($result)) 926 { 927 // for each user 928 foreach ($user_id as $i => $userid) 929 { 930 if (!isset($global_note_mod1[$row['image_id']])) 931 $global_note_mod1[$row['image_id']] = 0; 932 $globalnote_user = $this->get_img_globalnote_user($row['image_id'], null, $userid, null, 1, $vote_by_user[$userid]['average']); 933 934 $global_note_mod1[$row['image_id']] += ($globalnote_user >= 0 ? $globalnote_user : 0) ; 935 936 if (!isset($global_note_mod2[$row['image_id']])) 937 $global_note_mod2[$row['image_id']] = 0; 938 $globalnote_user = $this->get_img_globalnote_user($row['image_id'], null, $userid, null, 2, $vote_by_user[$userid]['moderation']); 939 940 $global_note_mod2[$row['image_id']] += ($globalnote_user >= 0 ? $globalnote_user : 0) ; 941 } 942 943 // for each guest 944 foreach ($ipguest as $i => $userid) 945 { 946 if (!isset($global_note_mod1[$row['image_id']])) 947 $global_note_mod1[$row['image_id']] = 0; 948 $globalnote_user = $this->get_img_globalnote_user($row['image_id'], null, null, $userid, 1, $vote_by_user[$userid]['average']); // userid contains the ip addr for the guest 949 950 $global_note_mod1[$row['image_id']] += ($globalnote_user >= 0 ? $globalnote_user : 0) ; 951 952 if (!isset($global_note_mod2[$row['image_id']])) 953 $global_note_mod2[$row['image_id']] = 0; 954 $globalnote_user = $this->get_img_globalnote_user($row['image_id'], null, null, $userid, 2, $vote_by_user[$userid]['moderation']); 955 956 $global_note_mod2[$row['image_id']] += ($globalnote_user >= 0 ? $globalnote_user : 0) ; 957 } 958 959 960 } 961 762 962 763 963 // update database and store result into RESULT table 764 964 // note = global note 765 965 $IMGmoyenne = 0; 966 $IMGmoyenneModeration1 = 0; 967 $IMGmoyenneModeration2 = 0; 968 766 969 foreach ($global_note as $id => $val) 767 970 // id contains the image id 768 971 { 769 if ($this->debug) echo $nbvotes[$id];770 972 $IMGmoyenne = (isset($nbvotes[$id]) && $nbvotes[$id] != 0 ? $val/$nbvotes[$id] : 0); 973 // Moderation 974 975 $IMGmoyenneModeration1 = ($nb_image_concours != 0 ? $global_note_mod1[$id]/$this->nb_user_by_concours() : 0); // all photos have note 976 $IMGmoyenneModeration2 = (isset($nbvotes[$id]) && $nbvotes[$id] != 0 ? $global_note_mod2[$id]/$nbvotes[$id] : 0); // only voted photos are used 771 977 772 $query = 'INSERT INTO ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note`, `moyenne`, `nbvotant` ) 978 $query = 'INSERT INTO ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note`, `moyenne`, 979 `moderation1`, `moderation2`, 980 `nbvotant` ) 773 981 VALUES ('.($concours_id !== null ? $concours_id : $this->concours_id ) 774 982 .', '.$id … … 776 984 .', '.$val 777 985 .', '.$IMGmoyenne 986 .', '.$IMGmoyenneModeration1 987 .', '.$IMGmoyenneModeration2 778 988 .', '.(isset($nbvotes[$id]) ? $nbvotes[$id] : 0) 779 989 .');'; 780 $result = pwg_query($query); 781 990 $result = pwg_query($query); 782 991 783 992 } 784 785 786 787 788 993 } 789 994 else … … 794 999 } 795 1000 796 797 // Check if an image's author is the same as the actual user 1001 1002 // Get array with nb of vote for each user of a concours_id 1003 function nb_user_by_concours($concours_id = NULL) 1004 { 1005 $nbusertotal = 0; 1006 // user 1007 $query = 'SELECT count(distinct(user_id)) as nb_user FROM ' . CONCOURS_DATA_TABLE .' 1008 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id).' 1009 AND ipguest IS NULL 1010 ;'; 1011 $result = pwg_query($query); 1012 if ($result) 1013 { 1014 $row = pwg_db_fetch_array($result); 1015 $nbusertotal += $row['nb_user']; 1016 } 1017 // guest 1018 $query = 'SELECT count(distinct(ipguest)) as nb_user FROM ' . CONCOURS_DATA_TABLE .' 1019 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id).' 1020 AND ipguest IS NOT NULL 1021 ;'; 1022 $result = pwg_query($query); 1023 if ($result) 1024 { 1025 $row = pwg_db_fetch_array($result); 1026 $nbusertotal += $row['nb_user']; 1027 } 1028 return $nbusertotal; 1029 1030 } 1031 1032 1033 // Check if an image's author OR addebBy is the same as the actual user 1034 // depending the config param 798 1035 function check_img_user($img_id) 799 1036 { 800 1037 global $user; 1038 1039 801 1040 $query = ' 802 SELECT author 1041 SELECT author, added_by 803 1042 FROM ' . IMAGES_TABLE .' 804 1043 WHERE id =' . $img_id . ' … … 809 1048 if ($result) 810 1049 { 811 $row = mysql_fetch_assoc($result);1050 $row = pwg_db_fetch_array($result); 812 1051 $authorid = get_userid($row['author']); 813 if ($authorid and ($authorid == $user['id'])) 814 return true; 815 else 816 return false; 1052 $addedbyid = $row['added_by']; 1053 1054 switch ($this->my_config['author_vote_available']) 1055 { 1056 1057 case 0 : // no check (allow to vote for all photos) 1058 return false; 1059 1060 case 1 : // check between author and user 1061 if ($authorid) // Author name present as username 1062 { 1063 if ($authorid == $user['id']) 1064 return true; 1065 else 1066 return false; 1067 } 1068 else 1069 { 1070 // check if author name = user name 1071 $AuthorArray = strip_punctuation2($row['author']); 1072 $UserArray = strip_punctuation2($user['username']); 1073 // Patch if author is empty 1074 if (empty($AuthorArray)) 1075 return false; 1076 1077 if (count(array_intersect($AuthorArray, $UserArray)) == count ($AuthorArray)) // found 1078 return true; 1079 else 1080 return false; 1081 } 1082 1083 1084 case 2 : // check between author and user 1085 if (isset($addedbyid) AND $addedbyid == $user['id']) 1086 return true; 1087 else 1088 return false; 1089 case 3 : // check between author OR addedby and user 1090 // Check Author 1091 if ($authorid AND $authorid == $user['id']) // Author name present as username 1092 return true; 1093 else 1094 { 1095 // check if author name = user name 1096 $AuthorArray = strip_punctuation2($row['author']); 1097 $UserArray = strip_punctuation2($user['username']); 1098 if (empty($AuthorArray) AND (count(array_intersect($AuthorArray, $UserArray)) == count ($AuthorArray))) // found 1099 return true; 1100 } 1101 // check addebBy 1102 if (isset($addedbyid) AND $addedbyid == $user['id']) 1103 return true; 1104 1105 return false; 1106 1107 default : 1108 return false; 1109 1110 } 1111 817 1112 } 818 1113 return false; 819 820 1114 } 821 1115 … … 826 1120 // Step0 : if user = guest, check the concours param and store ip address to user name. 827 1121 // Step1 : concours is defined to this category AND concours is open AND user is authorized to access to this category (thru group) 828 // Step1 bis : dont show concours if img_author = user_id1122 // Step1 bis : dont show concours if check author or added_by id is the samie as used_id (depending the param) 829 1123 // Step 2 : Recover stored informations in db for this user 830 1124 // Step 3 : Complete tpl information … … 839 1133 840 1134 // STEP 0 841 if ($this->debug) echo "STEP0\n"; 842 843 $user['ipguest'] = null; 844 845 echo "user id=".$user['id']; 846 // Check if the user is a guest only 847 if (is_a_guest()) 848 { 849 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 850 $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; 851 elseif(isset($_SERVER['HTTP_CLIENT_IP'])) 852 $IP = $_SERVER['HTTP_CLIENT_IP']; 853 else 854 $IP = $_SERVER['REMOTE_ADDR']; 855 856 // store ip 857 $user['ipguest'] = $IP; 858 if ($this->debug) 859 echo "user ip guest=".$user['ipguest']; 860 861 } 862 863 864 865 // DEBUG 866 if ($this->debug) 867 { 868 foreach ($user as $id=>$val) 869 { 870 if (is_array($val)) 871 foreach ($val as $id2=>$val2) 872 echo "user[".$id."][".$id2."]=".$val2."\n"; 873 else 874 echo "user[".$id."]=".$val."\n"; 875 } 876 } 877 878 // END DEBUG 1135 $user['ipguest'] = null; 1136 1137 // Check if the user is a guest only 1138 if (is_a_guest()) 1139 { 1140 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 1141 $IP = $_SERVER['HTTP_X_FORWARDED_FOR']; 1142 elseif(isset($_SERVER['HTTP_CLIENT_IP'])) 1143 $IP = $_SERVER['HTTP_CLIENT_IP']; 1144 else 1145 $IP = $_SERVER['REMOTE_ADDR']; 1146 1147 // store ip 1148 $user['ipguest'] = $IP; 1149 } 879 1150 880 1151 881 // DEBUG 882 if ($this->debug) 883 foreach ($page as $id=>$val) 884 { 885 if (is_array($val)) 886 foreach ($val as $id2=>$val2) 887 echo "page[".$id."][".$id2."]=".$val2."\n"; 888 else 889 echo "page[".$id."]=".$val."\n"; 890 } 891 // END DEBUG 892 893 // disable author name on image which are present in a concours. 894 // check the categories where the current image is present and disable the author name 1152 // disable author name on image which are present in a concours. 1153 // check the categories where the current image is present and disable the author name 895 1154 if (isset($this->my_config['mask_author']) && $this->my_config['mask_author'] == true) 896 1155 { … … 902 1161 WHERE image_id = '.$page['image_id'].' 903 1162 ;'; 904 // echo $query;905 1163 $result = pwg_query($query); 906 1164 $related_categories = array(); 907 while ($row = mysql_fetch_array($result))1165 while ($row = pwg_db_fetch_array($result)) 908 1166 { 909 1167 array_push($related_categories, $row['category_id']); … … 920 1178 AND time_to_sec(TIMEDIFF(now(), end_date)) < 0 921 1179 '; 922 // echo $query;923 1180 $result = pwg_query($query); 924 1181 // If one or more concours are found, the author name is masked 925 if ($result && mysql_fetch_assoc($result)) 926 { 927 $template->assign('INFO_AUTHOR',l10n('concours_img_author')); 928 } 929 } 930 } 931 932 // End disable author name 933 934 935 if (($page['section']) == 'categories' AND !empty($page['category'])) 936 { 937 if ($this->debug) echo "STEP1\n"; 938 //------------ 939 // Step 1 940 941 /* 942 if ($this->my_config['mask_author'] && $this->my_config['mask_author'] == true) 943 { 944 // Request for all concours prepared & actived 945 $query = ' 946 SELECT * 947 FROM ' . CONCOURS_TABLE .' 948 WHERE category =' . $page['category']['id'] . ' 949 AND time_to_sec(TIMEDIFF(now(), end_date)) < 0 950 '; 951 // echo $query; 952 $result = pwg_query($query); 953 if ($result && mysql_fetch_assoc($result)) 1182 if ($result && pwg_db_fetch_array($result)) 954 1183 $template->assign('INFO_AUTHOR',l10n('concours_img_author')); 955 1184 } 956 */ 1185 } 1186 1187 // End disable author name 1188 1189 1190 if (($page['section']) == 'categories' AND !empty($page['category'])) 1191 { 1192 // Step 1 957 1193 958 1194 $query = ' … … 965 1201 966 1202 $result = pwg_query($query); 967 if ($this->debug) echo $query."\n"; 968 while ($row = mysql_fetch_assoc($result))1203 1204 while ($row = pwg_db_fetch_array($result)) 969 1205 { 970 if (! empty($row['groups']))1206 if (!is_a_guest() AND !empty($row['groups'])) 971 1207 { 972 if ($this->debug) echo "GROUPS=".$row['groups']; 973 $authorized_groups = explode(',', $row['groups']); 974 if (array_intersect($this->user_groups, $authorized_groups) == array()) 975 { 976 if ($this->debug) echo "ERROR GROUPS"; 977 continue; 1208 1209 if (is_admin() AND $row['admin']) // allow admin 1210 $concours = $row; 1211 else 1212 { 1213 $authorized_groups = explode(',', $row['groups']); 1214 if (array_intersect($this->user_groups, $authorized_groups) == array()) 1215 continue; 1216 // If no group is parameter for that concours ==> available for all registered users 1217 $concours = $row; 978 1218 } 979 // If no group is parameter for that concours ==> available for all registered users980 $concours = $row;981 1219 } 982 else 1220 else 1221 983 1222 $concours = $row; 984 985 986 1223 } 987 988 if ($this->debug) echo "STEP1 bis\n";989 1224 //------------ 990 1225 // Step 1 bis 991 1226 // Actual user is the author of the picture ==>end 992 if ( !$this->my_config['author_vote_available']993 AND$this->check_img_user($page['current_item']))1227 // for the image, check (depending the config) if user = author or addedby or none 1228 if ($this->check_img_user($page['current_item'])) 994 1229 return; 995 996 997 if ($this->debug) echo "STEP2\n"; 1230 1231 // Check if user is guest and if guest is allowed 1232 if (is_a_guest() AND array_key_exists('guest', $concours) AND !$concours['guest']) 1233 return; 1234 // Check if user is admin and if admin is allowed 1235 if (is_admin() AND (!isset($concours['admin']) OR (isset($concours['admin']) AND !$concours['admin']))) 1236 return; 1237 998 1238 //------------ 999 1239 // Step 2 … … 1003 1243 if (isset($_POST['concours_submit'])) 1004 1244 { 1005 1245 1006 1246 // array_push($page['infos'] , l10n('concours_vote_saved')); 1007 1247 1008 1248 $user_note = ""; 1009 if ($this->debug) echo "SUBMIT"; 1010 // concat all the notes to save on db 1011 1249 1250 // concat all the notes to save on db 1012 1251 $firstcriterias = $this->get_firstlevel_criterias($concours['id']); 1013 1252 foreach ($firstcriterias as $criteria) 1014 1253 { 1015 1016 1254 // First without sub criterias 1017 1255 if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours['id'] )) 1018 1256 { 1019 1257 // Check value 1020 $value = str_replace(",",".", $_POST[$criteria['criteria_id']]);1258 $value = str_replace(",",".",(isset($_POST[$criteria['criteria_id']]) ? $_POST[$criteria['criteria_id']] : floatval($criteria['min_value']))); 1021 1259 $value = str_replace(" ","",$value); 1022 1260 $value = floatval($value); … … 1034 1272 { 1035 1273 // Check value 1036 $value = str_replace(",",".", $_POST[$subcriteria['criteria_id']]);1274 $value = str_replace(",",".",(isset($_POST[$subcriteria['criteria_id']]) ? $_POST[$subcriteria['criteria_id']] : floatval($subcriteria['min_value'] ))); 1037 1275 $value = str_replace(" ","",$value); 1038 1276 $value = floatval($value); … … 1047 1285 } 1048 1286 1049 // $datas = "0=0";1050 1287 $this->store_img_note_user($page['current_item'], $user_note, $concours['id'], $user['ipguest']); 1051 if ($this->debug) echo "COMMENT=".$_POST['CONCOURS_COMMENT'];1052 1288 $this->store_img_comment_user($page['current_item'], $_POST['concours_comment'], $concours['id'], $user['ipguest']); 1053 1289 } … … 1056 1292 if (isset($_POST['concours_raz'])) 1057 1293 { 1058 if ($this->debug) echo "RAZ"; 1059 $ this->RAZ_img_note_user($page['current_item'], $concours['id'], $user['ipguest']);1294 $this->delete_img_note_user($page['current_item'], $concours['id'], $user['ipguest']); 1295 $user_notes = array(); 1060 1296 } 1061 1297 else … … 1068 1304 $comment = $this->get_img_comment_user($page['current_item'], $concours['id'], $user['id'], $user['ipguest']); 1069 1305 1070 if ($this->debug) echo "STEP3\n";1071 1306 //------------ 1072 1307 // Step 3 … … 1075 1310 foreach ($firstcriterias as $criteria) 1076 1311 { 1077 if ($this->debug) echo "criteriaID=".$criteria['criteria_id']."\n";1078 1312 // First without sub criterias 1079 1313 if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours['id'] )) … … 1102 1336 foreach ($secondcriterias as $subcriteria) 1103 1337 { 1104 if ($this->debug) echo "subcriteriaID=".$criteria['criteria_id']."\n";1105 1338 $template->append( 'concours_criteria', array( 1106 1339 'nosub' => true, … … 1123 1356 // if a user has already vote for this photo, check if the score change is allowed 1124 1357 1125 if ($this->debug) echo "change=".($this->my_config['concours_change_score'] ? "OK" : "KO"); 1358 1126 1359 if ($user_notes == array() OR $this->my_config['concours_change_score']) // Allow user to change his vote after a validation 1127 1360 $template->assign( 'CONCOURS_CHANGE_SCORE', true); … … 1129 1362 $template->assign( 'CONCOURS_CHANGE_SCORE', false); 1130 1363 1131 1364 $noteuser = $this->get_img_globalnote_user($page['current_item'], $concours['id'], null, $user['ipguest']); 1132 1365 // Add concours informations on template 1133 1366 $template->assign( 'concours_infos', array( 1134 1367 'name' => $concours['name'], 1135 1368 'descr' => $concours['descr'], 1136 'note' => $this->get_img_globalnote_user($page['current_item'], $concours['id'], null, $user['ipguest']) 1369 'note' => ($noteuser >= 0 ? $noteuser : 0 ), 1370 'begin_date' => $concours['begin_date'], 1371 'end_date' => $concours['end_date'], 1372 'end_concours_min' => (strtotime($concours['end_date'])-time()) , 1373 'max_note' => $this->get_concours_maxnote($concours['id']), 1374 'deadline_type' => $this->my_config['concours_deadline'] 1137 1375 )); 1138 1376 1377 1378 $template->assign( 'SCORE_MODE', $this->my_config['score_mode']); 1379 $template->assign( 'TEXT_OVERLAY', $this->my_config['text_overlay']); 1139 1380 1140 1381 $template->set_filenames(array('concours' => CONCOURS_ROOT.'/template/concours.tpl')); 1141 // $template->concat('PLUGIN_PICTURE_AFTER', $template->parse('concours', true));1142 1382 $template->concat('COMMENT_IMG', $template->parse('concours', true)); 1143 1383 1144 //1145 1384 $template->assign('INFO_AUTHOR',l10n('concours_img_author')); 1146 1385 } … … 1148 1387 } 1149 1388 1389 1390 // RAZ notation from user to db 1391 // fill criterias notes to 0 in DB 1392 // return false if error 1393 function delete_img_note_user($img_id, $concours_id = NULL, $ipguest = null, $userid=null) 1394 { 1395 global $user; 1396 1397 if ($concours_id === null) 1398 if ($this->concours_id !== null) 1399 $concours_id = $this->concours_id; 1400 else 1401 return false; 1402 1403 $query = ' 1404 DELETE FROM ' . CONCOURS_DATA_TABLE .' 1405 WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ).' 1406 AND user_id = '.($userid == null ? $user['id'] : $userid).' 1407 AND img_id = '.$img_id. 1408 ($ipguest ? ' AND ipguest = "'.$ipguest.'"' : '') 1409 .';'; 1410 1411 return pwg_query($query); 1412 1413 } 1414 1415 1150 1416 // RAZ notation from user to db 1151 1417 // fill criterias notes to 0 in DB … … 1163 1429 foreach ($firstcriterias as $criteria) 1164 1430 { 1165 if ($this->debug) echo "ID=".$criteria['criteria_id']."\n";1166 1431 // First without sub criterias 1167 1432 if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id )) 1168 {1169 1433 $user_note .= (strlen($user_note) != 0 ? ";" : "").$criteria['criteria_id']."=".$criteria['min_value']; 1170 }1171 1434 else 1172 1435 { 1173 1436 $secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id ); 1174 1437 foreach ($secondcriterias as $subcriteria) 1175 {1176 if ($this->debug) echo "ID=".$criteria['criteria_id']."\n";1177 1438 $user_note .= (strlen($user_note) != 0 ? ";" : "").$subcriteria['criteria_id']."=".$subcriteria['min_value']; 1178 }1179 1439 } 1180 1440 } 1181 if ($this->debug) echo "RAZ=>".$user_note."\n";1182 1441 if (strlen($user_note) != 0) 1183 1442 { … … 1187 1446 else 1188 1447 return false; 1189 1190 1191 1448 } 1192 1449 … … 1199 1456 { 1200 1457 $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . CONCOURS_DATA_TABLE . ' ;'; 1201 list($next_element_id) = mysql_fetch_array(pwg_query($query));1202 if ($this->debug) echo "Next_element=".$next_element_id."\n"; 1458 list($next_element_id) = pwg_db_fetch_array(pwg_query($query)); 1459 1203 1460 $query = ' 1204 1461 INSERT INTO ' . CONCOURS_DATA_TABLE .' … … 1229 1486 .';'; 1230 1487 } 1231 if ($this->debug) echo $query."\n"; 1232 pwg_query($query); 1488 pwg_query($query); 1233 1489 1234 1490 } … … 1240 1496 function get_img_note_user($img_id, $concours_id = NULL, $user_id = null, $ipguest = null) 1241 1497 { 1242 global $user ;1498 global $user, $conf; 1243 1499 $img_note = array(); 1244 1500 if ($concours_id!== null or $this->concours_id !== null) … … 1247 1503 SELECT datas 1248 1504 FROM ' . CONCOURS_DATA_TABLE .' 1249 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '1250 AND user_id = '. ($user_id !== null ? $user_id : $user['id']).'1251 AND img_id = '. $img_id .1252 ($ipguest ? ' AND ipguest = "'.$ipguest.'"' : '') 1505 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) 1506 . ($ipguest == null ? ' AND user_id = '. ($user_id !== null ? $user_id : $user['id']) 1507 : ' AND user_id = '.$conf['guest_id'] .' AND ipguest = "'.$ipguest.'"') 1508 .' AND img_id = '. $img_id 1253 1509 .';'; 1254 if ($this->debug) echo $query."\n";1255 $result = pwg_query($query);1256 1257 while ($row = mysql_fetch_assoc($result))1258 {1259 if ($this->debug) echo "row[data]=".$row['datas']."\n";1260 $datas = explode(";",$row['datas']);1261 foreach ($datas as $val)1262 {1263 if (strpos($val, '=') !== FALSE)1264 $img_note[substr($val, 0, strpos($val, '='))]=substr($val, strpos($val, '=')+1);1265 }1266 }1267 // DEBUG1268 if ($this->debug)1269 foreach ($img_note as $id=>$val)1270 {1271 if (is_array($val))1272 foreach ($val as $id2=>$val2)1273 echo "img_note[".$id."][".$id2."]=".$val2."\n";1274 else1275 echo "img_note[".$id."]=".$val."\n";1276 }1277 // END DEBUG1278 1279 return $img_note;1280 }1281 else1282 return array();1283 1284 1285 }1286 1287 1288 // get notation's user from db1289 // Return the global note for a picture id from a user1290 function get_img_globalnote_user($img_id, $concours_id = NULL, $user_id = null, $ipguest = null)1291 {1292 global $user;1293 $img_note = array();1294 $global_user_note = 0;1295 if ($concours_id!== null or $this->concours_id !== null)1296 {1297 $query = '1298 SELECT datas1299 FROM ' . CONCOURS_DATA_TABLE .'1300 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '1301 AND user_id = '. ($user_id !== null ? $user_id : $user['id']).'1302 AND img_id = '. $img_id .1303 1510 ($ipguest ? ' AND ipguest = "'.$ipguest.'"' : '') 1304 1511 .';'; 1305 1512 $result = pwg_query($query); 1306 1513 1307 while ($row = mysql_fetch_assoc($result)) 1514 while ($row = pwg_db_fetch_array($result)) 1515 1308 1516 { 1309 1517 $datas = explode(";",$row['datas']); … … 1315 1523 } 1316 1524 1525 return $img_note; 1526 } 1527 else 1528 return array(); 1529 } 1530 1531 1532 1533 // Return the max note for a concours 1534 function get_concours_maxnote($concours_id = NULL) 1535 { 1536 1537 if ($concours_id!== null or $this->concours_id !== null) 1538 { 1539 $query = ' 1540 SELECT SUM(max_value) AS TOTAL 1541 FROM ' . CONCOURS_DETAIL_TABLE .' 1542 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) 1543 .' AND uppercriteria IS NULL' 1544 .';'; 1545 1546 $result = pwg_query($query); 1547 if ($this->debug) echo "query=".$query."<br>\n"; 1548 1549 if ($row = pwg_db_fetch_array($result)) 1550 { 1551 return $row['TOTAL']; 1552 } 1553 else 1554 return -1; 1555 1556 } 1557 1558 1559 } 1560 1561 1562 1563 // get notation's user from db 1564 // Return the global note for a picture id from a user 1565 // if moderationMode = 1, the 'moderation' contains the GlobalAverage for all the concours 1566 // if moderationMode = 2, the 'moderation' contains the user moderation for all image that are voted by 1567 // return -1 if there is no vote for that user 1568 function get_img_globalnote_user($img_id, $concours_id = NULL, $user_id = null, $ipguest = null, $moderationMode = 0, $moderation = 0) 1569 { 1570 global $user, $conf; 1571 $img_note = array(); 1572 $global_user_note = -1; 1573 $note_found = false; 1574 if ($concours_id!== null or $this->concours_id !== null) 1575 { 1576 $query = ' 1577 SELECT datas 1578 FROM ' . CONCOURS_DATA_TABLE .' 1579 WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) 1580 . ($ipguest == null ? ' AND user_id = '. ($user_id !== null ? $user_id : $user['id']) 1581 : ' AND user_id = '.$conf['guest_id'] .' AND ipguest = "'.$ipguest.'"') 1582 .' AND img_id = '. $img_id 1583 .';'; 1584 $result = pwg_query($query); 1585 if ($this->debug) echo "query=".$query."<br>\n"; 1586 1587 while ($row = pwg_db_fetch_array($result)) 1588 { 1589 $global_user_note = 0; // init note if one vote is present 1590 $note_found = true; 1591 $datas = explode(";",$row['datas']); 1592 foreach ($datas as $val) 1593 { 1594 if (strpos($val, '=') !== FALSE) 1595 $img_note[substr($val, 0, strpos($val, '='))]=substr($val, strpos($val, '=')+1); 1596 } 1597 } 1598 1317 1599 $firstcriterias = $this->get_firstlevel_criterias($concours_id); 1318 1600 foreach ($firstcriterias as $criteria) 1319 1601 { 1320 if ($this->debug) echo "criteriaID=".$criteria['criteria_id']."\n";1321 1602 // First without sub criterias 1322 1603 if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id )) … … 1327 1608 else 1328 1609 { 1329 1330 1610 $secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id ); 1331 1611 foreach ($secondcriterias as $subcriteria) 1332 1612 { 1333 if ($this->debug) echo "subcriteriaID=".$subcriteria['criteria_id']."\n";1334 1613 if (isset($img_note[$subcriteria['criteria_id']])) 1335 1614 $global_user_note += (int)$subcriteria['ponderation'] * (float)$img_note[$subcriteria['criteria_id']]; 1336 1615 } 1337 1616 } 1338 1339 1617 } 1340 1618 1619 // MODERATION 1620 // moderation 1 => For each photo without note (user = author or user != author but no vote) add each user avaerage to the total of note and calcul the average 1621 // moderation 2 => For each photo with note, adapt/change all the value with the moderation value : user note + moderation. 1622 1623 if ($user_id !== null) // only for user 1624 { 1625 if ($moderationMode == 1 && !$note_found) 1626 { // Moderation1 1627 $global_user_note = $moderation; 1628 } 1629 elseif ($moderationMode == 2 && $note_found) 1630 { // Moderation2 1631 $global_user_note += $moderation; 1632 } 1633 1634 1635 } 1341 1636 return $global_user_note; 1342 1637 } … … 1354 1649 { 1355 1650 $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . CONCOURS_DATA_TABLE . ' ;'; 1356 list($next_element_id) = mysql_fetch_array(pwg_query($query));1357 if ($this->debug) echo "Next_element=".$next_element_id."\n"; 1651 list($next_element_id) = pwg_db_fetch_array(pwg_query($query)); 1652 1358 1653 $query = ' 1359 1654 INSERT INTO ' . CONCOURS_DATA_TABLE .' … … 1381 1676 .';'; 1382 1677 } 1383 if ($this->debug) echo $query."\n";1384 1678 pwg_query($query); 1385 1386 1679 } 1387 1680 … … 1402 1695 ($ipguest ? ' AND ipguest = "'.$ipguest.'"' : '') 1403 1696 .';'; 1404 if ($this->debug) echo $query."\n"; 1697 1405 1698 $result = pwg_query($query); 1406 1699 1407 while ($row = mysql_fetch_assoc($result)) 1408 { 1409 if ($this->debug) echo "row[comment]=".$row['comment']."\n"; 1700 while ($row = pwg_db_fetch_array($result)) 1410 1701 $datas = $row['comment']; 1411 }1412 1702 } 1413 1703 return $datas; … … 1441 1731 // For each images 1442 1732 $rang = 1; 1443 while ($row = mysql_fetch_assoc($result))1733 while ($row = pwg_db_fetch_array($result)) 1444 1734 { 1445 1735 $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', ' … … 1467 1757 { 1468 1758 global $conf; 1759 $MethodType = "0"; 1469 1760 if ($concours_id === null) 1470 1761 $concours_id = $this->concours_id; … … 1495 1786 $ident1++; 1496 1787 } 1497 if ($this->debug) echo "CRITERIA_LIST=".$criteria_list."\n";1498 1788 $user_list = array(); 1499 1789 $users_criteria = ""; … … 1511 1801 $result = pwg_query($query); 1512 1802 // For each user 1513 while ($row = mysql_fetch_assoc($result))1803 while ($row = pwg_db_fetch_array($result)) 1514 1804 { 1515 1805 array_push($user_list, $row); 1516 1806 $users_criteria .= (strlen($users_criteria) ? "," : "")."user, user_global_note, comment, ".$criteria_list; 1517 1518 1807 } 1519 1808 … … 1530 1819 } 1531 1820 1532 if ($this->debug) echo "users_criteria=".$users_criteria."\n";1533 1821 1534 1822 // All informations in csv format 1535 $file = "rang, id_concours, method, nom_concours, date_debut, date_fin, date_export, img_id, img_name, img_file, img_author, note, moyenne, nbvotant, datas,"1823 $file = "rang, id_concours, method, nom_concours, date_debut, date_fin, date_export, img_id, img_name, img_file, img_author, note, moyenne, moderation1, moderation2, nbvotant, datas," 1536 1824 .$users_criteria 1537 1825 ."\r\n"; … … 1542 1830 $nbvotes = $this->nb_votes_by_img($concours_id); 1543 1831 1544 1545 1832 // recover all img_id from the category 1546 1833 if (!(isset($this->concours_infos['method']))) 1547 1834 $this->concours_infos['method'] = 1; 1548 $query = 'SELECT id_concours, method, img_id, IMG.name, IMG.file, IMG.author, date, note, moyenne, nbvotant, datas, comment'1835 $query = 'SELECT id_concours, method, img_id, IMG.name, IMG.file, IMG.author, date, note, moyenne, moderation1, moderation2, nbvotant, datas, comment' 1549 1836 .' FROM ' .CONCOURS_RESULT_TABLE 1550 1837 .' INNER JOIN ' . CONCOURS_TABLE.' AS CONC on CONC.id = id_concours' … … 1552 1839 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ); 1553 1840 1554 if ($this->concours_infos['method'] == 1) // total 1841 switch ($this->concours_infos['method']) 1842 { 1843 case 1 : // total 1555 1844 $query .= ' ORDER BY note DESC'; 1556 elseif ($this->concours_infos['method'] == 2) // moyenne 1845 $MethodType = "1-Sum"; 1846 break; 1847 case 2 : // moyenne 1557 1848 $query .= ' ORDER BY moyenne DESC'; 1558 1849 $MethodType = "2-Average"; 1850 break; 1851 case 3 : // moderation1 1852 $query .= ' ORDER BY moderation1 DESC'; 1853 $MethodType = "3-Average(Mod1)"; 1854 break; 1855 case 4 : // moderation2 1856 $query .= ' ORDER BY moderation2 DESC'; 1857 $MethodType = "4-Average(Mod2)"; 1858 break; 1859 } 1860 1559 1861 $query .=';'; 1560 1862 1561 if ($this->debug) echo $query;1562 1863 $result = pwg_query($query); 1563 1864 // For each images … … 1565 1866 $previousNote = $previousMoy = 0; 1566 1867 1567 while ($row = mysql_fetch_assoc($result))1868 while ($row = pwg_db_fetch_array($result)) 1568 1869 { 1569 1870 // Check and verify for exaequo … … 1575 1876 AND ($row['moyenne'] == $previousMoy))) 1576 1877 { 1577 $rang --; 1578 1878 $rang --; 1579 1879 } 1580 1880 } … … 1582 1882 $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', ' 1583 1883 .$row['id_concours'].', ' 1584 .$ row['method'].', '1884 .$MethodType.', ' 1585 1885 .str_replace(",", "",$this->concours_infos['name']).', ' 1586 1886 .$this->concours_infos['begin_date'].', ' … … 1594 1894 .$row['note'].', ' 1595 1895 .$row['moyenne'].', ' 1896 .$row['moderation1'].', ' 1897 .$row['moderation2'].', ' 1596 1898 .$row['nbvotant'].', ' 1597 // .(isset($nbvotes[$row['img_id']]) ? $nbvotes[$row['img_id']] : 0).', '1598 1899 .($row['datas'] != null ? $row['datas'] : '') 1599 1900 ; … … 1605 1906 $user_note = $this->get_img_note_user($row['img_id'], $concours_id, $uuser['user_id']); 1606 1907 1607 $ file .= ', '.$uuser['username'].', '.$this->get_img_globalnote_user($row['img_id'], $concours_id, $uuser['user_id'])1608 // .', '.($row['comment'] != null ? str_replace(",", "",$row['comment']) : '')1908 $user_global_note = $this->get_img_globalnote_user($row['img_id'], $concours_id, $uuser['user_id']); 1909 $file .= ', '.$uuser['username'].', '.($user_global_note >= 0 ? $user_global_note : 0) 1609 1910 .', '.($comment != false ? str_replace(array(",","\r\n", "\n", "\r"), " ",$comment) : '') 1610 1911 .', ' … … 1642 1943 foreach ($ipguest as $ipguestt) 1643 1944 { 1644 // echo "IP=".$ipguestt."\n";1645 1945 $comment = $this->get_img_comment_user($row['img_id'], $concours_id, $conf['guest_id'], $ipguestt); 1646 1946 1647 1947 $user_note = $this->get_img_note_user($row['img_id'], $concours_id, $conf['guest_id'], $ipguestt); 1648 1649 $file .= ', Guest('.$ipguestt.'), '.$this->get_img_globalnote_user($row['img_id'], $concours_id, $conf['guest_id'], $ipguestt)1650 // .', '.($row['comment'] != null ? str_replace(",", "",$row['comment']) : '')1948 $user_global_note = $this->get_img_globalnote_user($row['img_id'], $concours_id, $conf['guest_id'], $ipguestt); 1949 1950 $file .= ', Guest('.$ipguestt.'), '.($user_global_note >= 0 ? $user_global_note : 0) 1651 1951 .', '.($comment != false ? str_replace(array(",","\r\n", "\n", "\r"), " ",$comment) : '') 1652 1952 .', ' … … 1687 1987 1688 1988 } 1689 if ($this->debug) echo $file;1690 1989 return utf8_decode($file); 1691 1990 1692 1991 1693 1992 } 1694 1695 1993 1696 1994 … … 1722 2020 ;"; 1723 2021 pwg_query($query); 1724 if ($this->debug) echo $query;1725 2022 1726 2023 return $filename; … … 1735 2032 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ) 1736 2033 .';'; 1737 if ($this->debug) echo $query;1738 2034 $result = pwg_query($query); 1739 2035 if ($result) 1740 2036 { 1741 $row = mysql_fetch_assoc($result);2037 $row = pwg_db_fetch_array($result); 1742 2038 if ($row) 1743 2039 return $row['file_name']; … … 1762 2058 fpassthru($file); 1763 2059 } 1764 1765 }1766 1767 // Activation page administration 2060 } 2061 2062 // DEPRECATED Piwigo 11 Activation page administration 2063 /* 1768 2064 function concours_admin_menu($menu) 1769 2065 { … … 1771 2067 array( 1772 2068 'NAME' => CONCOURS_NAME, 1773 'URL' => get_ admin_plugin_menu_link(CONCOURS_ADMIN_PATH.'admin.php')2069 'URL' => get_root_url().'admin.php?page=plugin-'.CONCOURS_DIR.'-manage' 1774 2070 ) 1775 2071 ); 1776 2072 return $menu; 1777 2073 } 2074 */ 1778 2075 1779 2076 // register Concours Menubar 1780 2077 public function register_blocks( $menu_ref_arr ) 1781 2078 { 1782 $menu = & $menu_ref_arr[0];1783 if ($menu->get_id() != 'menubar' OR $this->my_config['active_menubar'] == false)1784 return;1785 $menu->register_block( new RegisteredBlock( 'CONCOURS_menu', 'concours', 'ConcoursPhoto'));2079 $menu = & $menu_ref_arr[0]; 2080 if ($menu->get_id() != 'menubar' OR $this->my_config['active_menubar'] == false) 2081 return; 2082 $menu->register_block( new RegisteredBlock( 'CONCOURS_menu', 'concours', 'ConcoursPhoto')); 1786 2083 } 1787 2084 … … 1789 2086 public function blockmanager_apply( $menu_ref_arr ) 1790 2087 { 1791 2088 1792 2089 global $user, $template; 1793 2090 $menu = & $menu_ref_arr[0]; … … 1798 2095 if ( ($block = $menu->get_block( 'CONCOURS_menu' ) ) != null ) 1799 2096 { 1800 1801 $menu_list=array(); 1802 1803 if(is_admin())1804 { 2097 $menu_list=array(); 2098 2099 if(is_admin()) 2100 { 2101 1805 2102 array_push($menu_list, 1806 2103 array( 1807 ' nfo' => "",1808 ' text' => l10n('concours_admin_add'),1809 ' link' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&action=new',1810 ' edit' => ""2104 'NAME' => l10n('concours_admin_add'), 2105 'TITLE' => l10n('concours_admin_add'), 2106 'URL' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&action=new', 2107 'REL' => "" 1811 2108 ) 1812 2109 ); 1813 } 2110 2111 } 1814 2112 1815 2113 // recover all img_id from the category 1816 $query = 'SELECT distinct(id_concours), groups, guest, CONC.name'2114 $query = 'SELECT distinct(id_concours), groups, guest, admin, CONC.name' 1817 2115 .' FROM ' .CONCOURS_RESULT_TABLE 1818 2116 .' INNER JOIN '.CONCOURS_TABLE. ' AS CONC ON CONC.id = id_concours' … … 1822 2120 $result = pwg_query($query); 1823 2121 $nb_concours = 1; 2122 1824 2123 // For each concours 1825 while ($row = mysql_fetch_assoc($result)) 2124 while ($row = pwg_db_fetch_assoc($result)) 2125 1826 2126 { 1827 2127 … … 1831 2131 $conc_to_show = false; // Default ==> dont show 1832 2132 1833 // Guest 1834 if (is_a_guest() AND $row['guest']) 2133 // Guest OR admin 2134 if ((is_a_guest() AND $row['guest']) 2135 OR (is_admin() AND $row['admin'])) 1835 2136 $conc_to_show = true; 1836 2137 // Group present 2138 2139 1837 2140 elseif (!empty($row['groups'])) 1838 2141 { … … 1848 2151 { 1849 2152 $nb_concours ++; 2153 1850 2154 array_push($menu_list, 1851 2155 array( 1852 ' nfo' => "",1853 ' text' => $row['name'],1854 ' link' => './index.php?/concours/'.$row['id_concours'],1855 ' edit' => (is_admin()? PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&concours=' . $row['id_concours'].'&action=modify':"")2156 'NAME' => $row['name'], 2157 'TITLE' => $row['name'], 2158 'URL' => './index.php?/concours/'.$row['id_concours'], 2159 'EDIT' => (is_admin()? PHPWG_ROOT_PATH . 'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&concours=' . $row['id_concours'].'&action=modify':"") 1856 2160 ) 1857 2161 ); … … 1861 2165 if (count($menu_list)) 1862 2166 { 1863 1864 $block->set_title(l10n('concoursphoto'));1865 2167 $block->template = CONCOURS_ROOT.'/template/concours_menu.tpl'; 1866 2168 $block->data = $menu_list; … … 1869 2171 } 1870 2172 1871 1872 2173 function section_init_concours() 1873 2174 { … … 1875 2176 if ($tokens[0] == 'concours') 1876 2177 $page['section'] = 'concours'; 2178 elseif ($tokens[0] == 'concours_vote') 2179 $page['section'] = 'concours_vote'; 1877 2180 } 1878 2181 … … 1880 2183 { 1881 2184 global $page; 1882 1883 1884 2185 if (isset($page['section']) and $page['section'] == 'concours') 1885 2186 { … … 1888 2189 } 1889 2190 2191 function index_vote_concours() 2192 { 2193 global $page; 2194 if (isset($page['section']) and $page['section'] == 'concours_vote') 2195 { 2196 include(CONCOURS_PATH . 'concours_vote.php'); 2197 } 2198 } 2199 1890 2200 1891 2201 // Show the global note under the thumbnail 1892 function thumbnail_note($tpl_var )2202 function thumbnail_note($tpl_var, $pictures) 1893 2203 { 1894 1895 global $page, $user; 2204 global $page, $user, $template; 1896 2205 $this->get_user_groups(); 1897 2206 … … 1909 2218 $user['ipguest'] = $IP; 1910 2219 } 1911 1912 if ($this->my_config['thumb_note'] && $this->my_config['thumb_note'] == true) 1913 { 1914 $concours = array(); 1915 if (($page['section']) == 'categories' AND !empty($page['category'])) 1916 { 1917 $query = ' 1918 SELECT * 1919 FROM ' . CONCOURS_TABLE .' 1920 WHERE category =' . $page['category']['id'] . ' 1921 AND time_to_sec(TIMEDIFF(begin_date,now())) < 0 1922 AND time_to_sec(TIMEDIFF(now(), end_date)) < 0 1923 '; 1924 1925 $result = pwg_query($query); 1926 if ($this->debug) echo $query."\n"; 1927 while ($row = mysql_fetch_assoc($result)) 1928 { 1929 1930 if (!empty($row['groups'])) 1931 { 1932 if ($this->debug) echo "GROUPS=".$row['groups']; 1933 $authorized_groups = explode(',', $row['groups']); 1934 if (array_intersect($this->user_groups, $authorized_groups) == array()) 1935 { 1936 if ($this->debug) echo "ERROR GROUPS"; 1937 continue; 1938 } 1939 $concours = $row; 1940 } 1941 1942 // If no group is parameter for that concours ==> available for all registered users 1943 else 1944 $concours = $row; 1945 1946 } 1947 if (count($concours)) 1948 { 1949 // Check if user is guest and if guest is allowed 1950 if ((is_a_guest() AND $concours['guest']) 1951 OR !is_a_guest()) 1952 { 1953 foreach($tpl_var as $cle=>$valeur) 1954 { 1955 // show only if the author is not the active user 1956 if ($tpl_var[$cle]['FILE_AUTHOR'] != $user['username'] 1957 OR $this->my_config['author_vote_available'] // Allow author to vote (and also show his score) 1958 ) 1959 { 1960 $tpl_var[$cle]['NAME'] = $tpl_var[$cle]['NAME'].'<br> '.l10n('thumbnail_global_note').' : '.$this->get_img_globalnote_user($tpl_var[$cle]['ID'], $concours['id'], $user['id'], $user['ipguest']); 1961 } 1962 } 1963 } 1964 } 1965 } 1966 } 2220 2221 if (($page['section']) == 'categories' AND !empty($page['category'])) 2222 { 2223 2224 $concours = array(); 2225 2226 $query = ' 2227 SELECT * 2228 FROM ' . CONCOURS_TABLE .' 2229 WHERE category =' . $page['category']['id'] 2230 // comment to load prepared contests and opened contests . ' AND time_to_sec(TIMEDIFF(begin_date,now())) < 0' 2231 . ' AND time_to_sec(TIMEDIFF(now(), end_date)) < 0'; 2232 2233 $result = pwg_query($query); 2234 // DEBUG 2235 if ($this->debug) echo $query."\n"; 2236 // END DEBUG 2237 while ($row = pwg_db_fetch_array($result)) 2238 { 2239 if ((strtotime($row['begin_date'])-time() > 0) AND $this->my_config['mask_thumbnail']) 2240 { 2241 // disable picture if contest is prepared for all users 2242 $i=0; 2243 while ($i<count($tpl_var)) 2244 { 2245 array_splice($tpl_var, $i, 1); 2246 array_splice($pictures, $i, 1); 2247 } 2248 $concours = $row; 2249 2250 } 2251 elseif (is_admin() AND $row['admin']) 2252 $concours = $row; 2253 elseif (!is_a_guest() AND !empty($row['groups'])) 2254 { 2255 $authorized_groups = explode(',', $row['groups']); 2256 if (array_intersect($this->user_groups, $authorized_groups) == array()) 2257 continue; 2258 $concours = $row; 2259 } 2260 2261 // If no group is parameter for that concours ==> available for all registered users 2262 else 2263 $concours = $row; 2264 } 2265 2266 2267 if (count($concours)) 2268 { 2269 // Add timeline for all users. 2270 if (strtotime($concours['begin_date'])-time() > 0) 2271 { 2272 $template->assign('begin_concours_min', (strtotime($concours['begin_date'])-time())); 2273 $template->assign('deadline_type',$this->my_config['concours_deadline']); 2274 $template->assign('begin_concours', $concours['begin_date']); 2275 } 2276 else 2277 { 2278 // Check if user is guest and if guest is allowed 2279 if ((is_a_guest() AND $concours['guest']) 2280 OR (is_admin() AND $concours['admin']) 2281 OR !is_a_guest()) 2282 { 2283 2284 // check if contest is concours not already open (date begin > now) 2285 2286 2287 2288 foreach($tpl_var as $cle=>$valeur) 2289 { 2290 // show only if the author is not the active user 2291 2292 $AuthorArray = strip_punctuation2($tpl_var[$cle]['author']); 2293 $AddedByID = ($tpl_var[$cle]['added_by']); 2294 $UserArray = strip_punctuation2($user['username']); 2295 2296 if ($this->my_config['author_vote_available'] == 0 // Allow to vote for all photos (and also show his score) 2297 OR ($this->my_config['author_vote_available'] == 1 // check between author and user 2298 AND (empty($AuthorArray) OR count(array_intersect($AuthorArray, $UserArray)) != count ($AuthorArray)) // Author is the same as user name 2299 ) 2300 OR ($this->my_config['author_vote_available'] == 2 // check between author and user 2301 AND (!isset($AddedByID) OR ($user['id'] != $AddedByID)) // Addedby is the same as user name 2302 ) 2303 OR ($this->my_config['author_vote_available'] == 3 // check between author OR addedby and user 2304 AND (!isset($AddedByID) OR ($user['id'] != $AddedByID)) // Addedby is the same as user name 2305 AND (empty($AuthorArray) OR count(array_intersect($AuthorArray, $UserArray)) != count ($AuthorArray)) // Author is the same as user name 2306 ) 2307 ) 2308 2309 { 2310 if ($this->my_config['thumb_note']) // display thumbnail note only if option is activated 2311 { 2312 $user_global_note = $this->get_img_globalnote_user($tpl_var[$cle]['id'], $concours['id'], $user['id'], $user['ipguest']); 2313 $tpl_var[$cle]['NAME'] = $tpl_var[$cle]['NAME'].'('.l10n('thumbnail_global_note').': '.($user_global_note >= 0 ? $user_global_note : 0).')'; 2314 } 2315 } 2316 } 2317 2318 // Add deadline on description page 2319 $template->assign('end_concours', $concours['end_date']); 2320 $template->assign('end_concours_min', (strtotime($concours['end_date'])-time())); 2321 $template->assign('deadline_type',$this->my_config['concours_deadline']); 2322 if (isset($this->my_config['active_global_score_page']) AND $this->my_config['active_global_score_page']) // only if option is activated 2323 $template->assign('global_vote_link', PHPWG_ROOT_PATH . 'index.php?/concours_vote/'.$concours['id']); 2324 } 2325 2326 } 2327 $template->assign('IMG_URL', CONCOURS_IMG_PATH); 2328 2329 $template->set_filenames(array('concours_description' => CONCOURS_ROOT.'/template/concours_description.tpl')); 2330 $template->concat('CONTENT_DESCRIPTION', $template->parse('concours_description', true)); 2331 2332 } 2333 } 2334 1967 2335 return $tpl_var; 1968 2336 } 1969 2337 2338 function concours_stuffs_module($modules) 2339 { 2340 array_push($modules, array( 2341 'path' => CONCOURS_PATH.'stuffs_module/', 2342 'name' => l10n('concours_stuffs_name'), 2343 'description' => l10n('concours_stuffs_description'), 2344 ) 2345 ); 2346 return $modules; 2347 } 2348 2349 2350 2351 function add_contest_desc($tpl_var) 2352 { 2353 global $page, $user, $template; 2354 // TO DO : Add contest information on subcategory 2355 /* 2356 echo "ICI<br>"; 2357 echo "tpl_VAR".(is_array($tpl_var) ? "OK" : $tpl_var)."<br>"; 2358 foreach ($tpl_var as $id=>$val) 2359 { 2360 2361 if (is_array($val)) 2362 foreach ($val as $id2=>$val2) 2363 if (is_array($val2)) 2364 foreach ($val2 as $id3=>$val3) 2365 if (is_array($val3)) 2366 foreach ($val3 as $id4=>$val4) 2367 echo "tpl_var[".$id."][".$id2."][".$id3."][".$id4."]=".$val4."<br>\n"; 2368 else 2369 echo "tpl_var[".$id."][".$id2."][".$id3."]=".$val3."<br>\n"; 2370 else 2371 echo "tpl_var[".$id."][".$id2."]=".$val2."<br>\n"; 2372 else 2373 echo "tpl_var[".$id."]=".$val."<br>\n"; 2374 } 2375 $i=0; 2376 while ($i<count($tpl_var)) 2377 { 2378 $tpl_var[$i]['NAME'] = "TEST TEST"; 2379 $i++; 2380 2381 } 2382 2383 $template->set_filenames(array('concours_description' => CONCOURS_ROOT.'/template/concours_description-cat.tpl')); 2384 $template->concat('DESCRIPTION', $template->parse('concours_description', true)); 2385 2386 return $tpl_var; 2387 */ 2388 } 2389 2390 2391 2392 2393 // Check if a concours is present (prepared or actived) for the category and user group 2394 function concours_present_cat($category = NULL) 2395 { 2396 global $page; 2397 $concours_present = false; 2398 if (!isset($category)) // param not present 2399 { 2400 if (($page['section']) == 'categories' AND !empty($page['category'])) 2401 $category = $page['category']['id'] ; 2402 } 2403 2404 if (isset($category)) 2405 { 2406 $query = ' 2407 SELECT * 2408 FROM ' . CONCOURS_TABLE .' 2409 WHERE category =' . $category . ' 2410 AND time_to_sec(TIMEDIFF(now(), end_date)) < 0 2411 '; 2412 2413 $result = pwg_query($query); 2414 while ($row = pwg_db_fetch_array($result)) 2415 return true; 2416 } 2417 return false; 2418 } 2419 2420 2421 // Disable Metatdata to picture for a prepared or active concours 2422 function disable_meta_to_picture() 2423 { 2424 if (isset($this->my_config['mask_meta']) && $this->my_config['mask_meta'] == true) 2425 { 2426 if ($this->concours_present_cat()) 2427 pwg_set_session_var('show_metadata', 0 ); 2428 } 2429 } 2430 1970 2431 1971 2432 } 1972 2433 2434 function strip_punctuation($string) { 2435 $string = strtolower($string); // lower case 2436 $string = preg_replace("/\p{P}+/", "", $string); // remove punctuation 2437 $string = preg_replace("/\p{Nd}+/", "", $string); // remove numeric 2438 $string = preg_replace("/[\p{Z}\t\r\n\v\f]+/", "", $string); // remove spaces 2439 $string = str_replace(" +", "", $string); // remove space 2440 //echo "stripPunct=".$string."!\n"; 2441 return $string; 2442 } 2443 2444 // return array 2445 function strip_punctuation2($string) { 2446 $string = strtolower($string); // lower case 2447 $string = preg_replace("/\p{P}+/", " ", $string); // remove punctuation by space 2448 $string = preg_replace("/\p{Nd}+/", "", $string); // remove numeric 2449 $string = preg_replace("/[\p{Z}\t\r\n\v\f]+/", " ", $string); // remove spaces by spaces (only 1) 2450 // $string = str_replace(" +", "", $string); // remove space 2451 $stringArray = $returnValue = preg_split('/\\W/', $string, -1, PREG_SPLIT_NO_EMPTY); 2452 2453 return $stringArray; 2454 } 2455 2456 2457 1973 2458 ?> -
extensions/ConcoursPhoto/include/default_values.inc.php
r8946 r32457 7 7 $concours_default_values['active_menubar'] = true; // Activate menubar view 8 8 $concours_default_values['nbconcours_menubar'] = 3; // Nb of last published concours show on concours menubar 9 $concours_default_values['mask_author'] = true; // Mask author for prepared concours 9 $concours_default_values['mask_author'] = true; // Mask author for prepared concours or active concours 10 $concours_default_values['mask_meta'] = false; // Mask meta for prepared concours or active concours 10 11 $concours_default_values['thumb_note'] = true; // Display global note (for user) under thumbnail 11 12 $concours_default_values['check_exaequo'] = false; // Check exaequo and display the same rank 12 $concours_default_values['author_vote_available'] = false; // Dont allow author to vote for his own photo 13 //$concours_default_values['author_vote_available'] = false; // Dont allow author to vote for his own photo 14 $concours_default_values['author_vote_available'] = 0; // 0: Disable check between curent user and Author/AddedBy info for a photo ==> All user cound vote 15 // 1: Check between "Author" (of photo) and "User" 16 // 2: Check between "AddedBy" (of photo) and "User" 17 // 3: Check between "Author" OR "AddedBy" and "User" 18 13 19 $concours_default_values['concours_change_score'] = true; // Allow a user to change his score afer a validation 20 $concours_default_values['concours_deadline'] = 2; // 0: dont show deadline; 1: deadline version 1; 2: deadline version 2 21 $concours_default_values['mask_thumbnail'] = true; // Mask thumbnail on category page before the contest start 22 $concours_default_values['nb_concours_page'] = 10; // nb of contest by page (on admin page) 23 $concours_default_values['active_global_score_page'] = false; // activate global page for vote/score (all image in 1 page) 24 $concours_default_values['score_mode'] = 1; // score mode. 0: text box / 1: stars 25 $concours_default_values['text_overlay'] = "Vote déjà enregistré <br>"; // text to display when the score is already present and the option concours_change_score is false (allow the user to change the score after vote) 14 26 15 27 ?>
Note: See TracChangeset
for help on using the changeset viewer.