Advertisement
Guest User

add_event

a guest
Jan 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.62 KB | None | 0 0
  1. function insert_array($table,$pairs,$getID='1',$debug='1'){
  2.     global $db;
  3.     if($debug=='1') $o .= $table;
  4.  
  5.     if(is_array($pairs)){
  6.         while(list($key,$value)=each($pairs)){
  7.             $pair[] = " `$key` = '".@mysql_real_escape_string($value)."'";
  8.         }
  9.         $set = implode(',',$pair);
  10.         $query = "INSERT INTO {$db}.`$table` SET $set";
  11.         if(@mysql_query($query)){
  12.             if($getID=='1'){
  13.                 if($ID = @mysql_insert_id()){
  14.                     $o .= "...OK($ID)\n";
  15.                     if($debug=='1') echo $o;
  16.                     return $ID;
  17.                 }else{
  18.                     $o .= "...OK(noID!)\n";
  19.                 }
  20.             }else{
  21.                 $o .= "...OK\n";
  22.                 if($debug=='1') echo $o;
  23.                 return 1;
  24.             }
  25.         }else{
  26.             $o .= "...INSERT ERROR\n";
  27.         }
  28.     }else{
  29.         $o .= "...wrong PAIRS!\n";
  30.     }
  31.     if($debug=='1') echo $o;
  32. }
  33.  
  34. function input_actSoccer($act,$count,$title=''){
  35.     global $db;
  36.     // trims
  37.     if(preg_match("~e\.a\.$~i",$act))       $act = preg_replace("~e\.a\.$~i","",$act);
  38.     elseif(preg_match("~e\.a$~i",$act)) $act = preg_replace("~e\.a$~i","",$act);
  39.     $out->title = trim($act);
  40.  
  41.     if(stristr($act,"(") AND stristr($act,")")){
  42.         $tmp = explode("(",$act);
  43.         $tmptit = $tmp[0];
  44.         $tmp = explode(")",$tmp[1]);
  45.         $tmp = dbformat($tmp[0]);
  46.  
  47.         // instruments
  48.         if($instrument = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.instrument WHERE name LIKE '$tmp' OR name_en LIKE '$tmp'"))){
  49.             $out->instrumentID = $instrument[0];
  50.             $out->title = trim($tmptit);
  51.             $out->element_table = 'person';
  52.         }
  53.         // professions
  54.         if($tmp == 'zang' OR $tmp == 'sopraan' OR $tmp == 'bariton'){
  55.             $out->persontypeID = 8;
  56.             //$out->title = trim($tmptit);
  57.             $out->element_table = 'person';
  58.         }
  59.     }
  60.  
  61.     // type gues
  62.     if(!$out->element_table){
  63.         if(preg_match("~^dj~i",$act) AND stristr($act,"dj ")){
  64.             $out->element_table = 'person';
  65.             $out->persontypeID = 13;
  66.         }elseif(strstr($act,"&") OR stristr($act," orchest") OR stristr($act," duo") OR stristr($act," duet")
  67.                 OR stristr($act," trio") OR stristr($act," quartet") OR stristr($act," kwartet") OR stristr($act," quintet")
  68.                 OR stristr($act," sextet") OR stristr($act," orkest") OR stristr($act,"group")
  69.                 OR stristr($act,"band") OR stristr($act,"groep") OR stristr($act,"ensemble")
  70.                 OR stristr($act,"philharmon") OR stristr($act,"filharmon") OR stristr($act,"circus")
  71.                 ){
  72.             $out->element_table = 'group';
  73.  
  74.         }
  75.     }
  76.     if(strstr($out->title,"+ support")){
  77.         $out->title = trim(str_replace("+ support","",$out->title));
  78.         $out->support = 'W';
  79.     }else{
  80.         $out->support = 'N';
  81.     }
  82.     return $out;
  83. }
  84.  
  85. function get_types($array,$table='eventtype',$debug='0'){
  86.     global $db;
  87.     $items = mysql_query("SELECT * FROM {$db}.$table");
  88.     while($item = mysql_fetch_object($items)){
  89.         reset($array);
  90.         while(list($_,$str) = each($array)){
  91.             if($debug=='1')     echo '<br>procesing '.$item->name." against $str";
  92.             if( stristr($item->name,$str) OR stristr($item->name_en,$str) ){
  93.                 $return[] = $item->ID;
  94.             }
  95.             if(strlen($item->keyw)>0){
  96.                 $keyw = explode(",",$item->keyw);
  97.                 //echo "..in keyw..";
  98.                 while(list($_,$word) = each($keyw)){
  99.                     if(stristr($word,$str) OR stristr($str,$word)){
  100.                         $return[] = $item->ID;
  101.                     }
  102.                 }
  103.             }
  104.             if($debug=='1')
  105.                 echo ', found:'.count($return);
  106.         }
  107.     }
  108.     if(is_array($return))
  109.         return array_unique($return);
  110. }
  111.  
  112. function get_image1($ID,$url,$title,$table='venue',$credits=''){
  113.     global $db,$auth_userID;
  114.     $url = str_replace(" ","%20",$url);
  115.     set_time_limit(120);
  116.     $info = getimagesize($url);
  117.     switch($info[2]) {
  118.         case 1: $itype = "image/gif"; break;
  119.         case 2: $itype = "image/jpeg";break;
  120.         case 3: $itype = "image/png"; break;
  121.         case 4: $itype = "application/x-shockwave-flash";break;
  122.     }
  123.     if($itype AND $info[0] > 20){
  124.         $check = mysql_num_rows(mysql_query("SELECT ID FROM {$db}.the_image WHERE URL = '$url' AND width = '{$info[0]}' AND height = '{$info[1]}'"));
  125.         if($check > 0){
  126.             // do nothing
  127.         }elseif($f = fopen($url,"rb")){
  128.             $content =  base64_encode(implode('',file($url)));
  129.             fclose($f);
  130.             $title = dbformat($title);
  131.             $desc = dbformat($desc);
  132.             $credits = dbformat($credits);
  133.             mysql_query("INSERT INTO {$db}.the_image SET
  134.                         title       = '$title',
  135.                         type        = '$itype',
  136.                         width       = '{$info[0]}',
  137.                         height      = '{$info[1]}',
  138.                         content     = '$content',
  139.                         description = '$desc',
  140.                         URL     = '$url',
  141.                         credits     = '$credits',
  142.                         userID      = '$auth_userID'");
  143.             sleep(1);
  144.             $imageID = mysql_insert_id();
  145.             if ($imageID>0){
  146.                 mysql_query("INSERT INTO {$db}.image_link SET
  147.                                 imageID     = '$imageID',
  148.                                 elementID   = '$ID',
  149.                                 element_table   = '$table',
  150.                                 medium      = 'PC'");
  151.                 return 1;
  152.             }
  153.         }
  154.     }
  155. }
  156.  
  157. function matchImportSalespoint($import_timesID,$agendaID){
  158.     global $db,$auth_userID;
  159.     //echo "tryin $import_timesID $agendaID<br>";
  160.     if($import_timesID > 0 AND $agendaID > 0){
  161.         $salespoint = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.import_salespoint WHERE element_table='import_times' AND elementID='$import_timesID'"));
  162.         $agenda = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.times WHERE ID='$agendaID'"));
  163.  
  164.         if($salespoint->ID>0 AND $agenda->ID>0){
  165.             //echo "found<br>";
  166.  
  167.             unset($description);
  168.             $event = new event($agenda->eventID);
  169.             $venue = new venue($agenda->venueID);
  170.             $place = new municipal($venue->municipalID);
  171.             $description[] = timestamp2time($agenda->period_from);
  172.             $description[] = $venue->name." - ".$place->name;
  173.             $description = implode(", ",$description);
  174.  
  175.             if($salespoint->description!='' AND strip_tags($salespoint->description) == $salespoint->description){
  176.                 $description .= ", ".$salespoint->description;
  177.             }
  178.  
  179.  
  180.             $description = dbformat($description);
  181.             $query = "INSERT INTO {$db}.salespoint SET element_table='times', elementID='$agendaID', vendorID='$salespoint->vendorID', vendorItemID='$salespoint->vendorItemID', ".
  182.                 "URL='{$salespoint->URL}', price='{$salespoint->price}', vendorItemImageURL='{$salespoint->vendorItemImageURL}', ".
  183.                 "userID='{$auth_userID}', title='$salespoint->title', description='$description'";
  184.             if(mysql_query($query)){
  185.                 return true;
  186.             }else{
  187.                 echo mysql_error();
  188.             }
  189.         }
  190.     }
  191. }
  192.  
  193. function add_event($ID,$debug='1'){
  194.     global $db,$site,$auth_userID;
  195.     if($item=mysql_fetch_object(mysql_query("SELECT * FROM {$db}.import_event WHERE ID='$ID'"))){
  196.  
  197.         $event[title] = $item->title;
  198.         $event[subtitle] = $item->subtitle;
  199.         $event[nature] = $item->nature;
  200.         $event[type_spec] = $item->type_spec;
  201.         $event[description] = str_replace("<br />","\n",$item->description);
  202.         if(strlen(trim($item->info))>0){
  203.             $event[temp_desc] .= "\n".$item->info;
  204.         }
  205.         $event[homepage] = $item->url;
  206.         $event[userID] = $auth_userID;
  207.  
  208.         // TRY TO INSERT FROM ARRAY
  209.         if($eventID = insert_array('event',$event,'1','0')){
  210.             $return->mssg = "OK event";
  211.             $return->nature = $item->nature;
  212.  
  213.             // check word lenght
  214.             if(strlen($event[type_spec])>17){
  215.                 $tmp = explode(" ",$event[type_spec]);
  216.                 while(list($_,$tmp1)=each($tmp)){
  217.                     if(strlen(trim($tmp1))>17){
  218.                         $type_spec_error = 1;
  219.                     }
  220.                 }
  221.                 if($type_spec_error){
  222.                     $return->mssg .= "<br /><b><span style='color:orange;'>WARNING: Type spec word(s) too long!</span></b>";
  223.                 }
  224.             }
  225.  
  226.             // store act(s)
  227.             $act = mysql_real_escape_string($item->act);
  228.  
  229.             if(strlen($act)>0){
  230.                 $tmp = explode(",",$act);
  231.                 $actcount = count($tmp);
  232.                 while(list($_,$tmp1)=each($tmp)){
  233.                     unset($actcheck);
  234.                     $tmp1obj = input_actSoccer(trim($tmp1),$actcount);
  235.                     $tmp1 = $tmp1obj->title;
  236.                     if(!($actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE elementID > 0 AND title LIKE '$tmp1' LIMIT 1")))){
  237.                         if(!($actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE elementID > 0 AND title LIKE '$tmp1%' LIMIT 1"))))
  238.                             $actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE title LIKE '$tmp1' LIMIT 1"));
  239.                     }
  240.                     if(!($actcheck->elementID > 0)){
  241.                         if($tmp1obj->element_table == 'person'){
  242.                             if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.person WHERE artname LIKE '$tmp1' ORDER BY checked DESC"))){
  243.                                 $actcheck->elementID = $dbActMatch[0];
  244.                             }elseif(mysql_query("INSERT INTO {$db}.person SET artname = '$tmp1', userID = '$auth_userID'")){
  245.                                 $actcheck->elementID = mysql_insert_id();
  246.                             }
  247.                             echo mysql_error();
  248.                             $actcheck->relationID = 1;
  249.                             $actcheck->element_table = 'person';
  250.                         }elseif($tmp1obj->element_table == 'group'){
  251.                             if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.`group` WHERE title LIKE '$tmp1' ORDER BY checked DESC"))){
  252.                                 $actcheck->elementID = $dbActMatch[0];
  253.                             }elseif(mysql_query("INSERT INTO {$db}.`group` SET title = '$tmp1', userID = '$auth_userID'")){
  254.                                 $actcheck->elementID = mysql_insert_id();
  255.                             }
  256.                             echo mysql_error();
  257.                             $actcheck->relationID = 1;
  258.                             $actcheck->element_table = 'group';
  259.                         }else{
  260.                             if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.person WHERE artname LIKE '$tmp1' ORDER BY checked DESC"))){
  261.                                 $actcheck->elementID = $dbActMatch[0];
  262.                                 $actcheck->element_table = 'person';
  263.                             }elseif($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.`group` WHERE title LIKE '$tmp1' ORDER BY checked DESC"))){
  264.                                 $actcheck->elementID = $dbActMatch[0];
  265.                                 $actcheck->element_table = 'group';
  266.                             }
  267.                             echo mysql_error();
  268.                             if($actcheck->elementID > 0){
  269.                                 $actcheck->relationID = 1;
  270.                             }
  271.                         }
  272.                     }
  273.                     if($actcheck->elementID > 0){
  274.                         if(stristr($event[title]," + support")){
  275.                             //$return->mssg .= "<br /><b><span style='color:orange;'>WARNING: &quot;+ support&quot; situation, event renamed!</span></b>";
  276.                             $newEventTitle = dbformat(str_replace(" + support","",$event[title]));
  277.                             mysql_query("UPDATE {$db}.event SET title = '$newEventTitle' WHERE ID = '$eventID'");
  278.                         }
  279.                         mysql_query("INSERT INTO {$db}.event_details SET title='$tmp1', eventID = '$eventID',
  280.                                 relationID='$actcheck->relationID', elementID='$actcheck->elementID',
  281.                                 element_table='$actcheck->element_table', instrumentID='$tmp1obj->instrumentID', persontypeID='$tmp1obj->persontypeID', support = '$actcheck->support'");
  282.                         echo mysql_error();
  283.                         if($tmp1obj->instrumentID > 0 AND $actcheck->element_table == 'person'){
  284.                             if(!(mysql_num_rows(mysql_query("SELECT * FROM {$db}.person_instrument WHERE personID='$actcheck->elementID' AND
  285.                                                 instrumentID = '$tmp1obj->instrumentID'"))>0)){
  286.                                     mysql_query("INSERT INTO {$db}.person_instrument SET personID='$actcheck->elementID', instrumentID = '$tmp1obj->instrumentID'");
  287.                                     echo mysql_error();
  288.                             }
  289.                         }
  290.                         if($tmp1obj->persontypeID > 0 AND $actcheck->element_table == 'person'){
  291.                             if(!(mysql_num_rows(mysql_query("SELECT * FROM {$db}.person_persontype WHERE personID='$actcheck->elementID' AND
  292.                                                 typeID = '$tmp1obj->persontypeID'"))>0)){
  293.                                     mysql_query("INSERT INTO {$db}.person_persontype SET personID='$actcheck->elementID', typeID = '$tmp1obj->persontypeID'");
  294.                                     echo mysql_error();
  295.                             }
  296.                         }
  297.                         $has_atc++;
  298.                     }else{
  299.                         if(stristr($event[title]," + support")){
  300.                             //$return->mssg .= "<br /><b><span style='color:orange;'>WARNING: &quot;+ support&quot; situation, event renamed!</span></b>";
  301.                             //$newEventTitle = dbformat(str_replace(" + support","",$event[title]));
  302.                             //mysql_query("UPDATE event SET title = '$newEventTitle' WHERE ID = '$eventID'");
  303.                         }
  304.                         mysql_query("INSERT INTO {$db}.event_details SET title='$tmp1', eventID = '$eventID', relationID = '1', support = '$actcheck->support'");
  305.                         echo mysql_error();
  306.                         $has_atc++;
  307.                     }
  308.                     echo mysql_error();
  309.                 }
  310.             }
  311.  
  312.             if($has_atc > 0){
  313.                 $return->mssg .= "<br /><b><span style='color:orange;'>WARNING: $has_atc act(s) has been added, please verify if correct. Also verify if act has been correctly linked!</span></b>";
  314.             }
  315.  
  316.             // STORE EVENT TYPES
  317.             if($item->siteID=='14'){
  318.                 $mtypes = mysql_query("SELECT * FROM {$db}.eventtype");
  319.                 while ($mtype = (mysql_fetch_object($mtypes))){
  320.                     $b = explode(",",$mtype->onstageIDs);
  321.                     while(list($_,$ostID) = each($b)){
  322.                         if($item->onstage_typeID==$ostID){
  323.                             $e_types[] = $mtype->ID;
  324.                         }
  325.                         //$bridge[$ostID] = $mtype->ID;
  326.                     }
  327.                 }
  328.             }else{
  329.                 if($itypes = mysql_query("SELECT * FROM {$db}.import_eventtype WHERE import_eventID = '$ID'")){
  330.                     while($itype = mysql_fetch_object($itypes)){
  331.                         if($itype->eventtypeID > 0){
  332.                             $e_types[] = $itype->eventtypeID;
  333.                             $have_et = 1;
  334.                             echo "<br>type imported";
  335.                         }
  336.                     }
  337.                 }
  338.                 if(!is_array($e_types) AND !$have_et){
  339.                     $gues_types[] = $item->type_spec;
  340.                     $e_types = get_types($gues_types,'eventtype','0');
  341.                     echo "<br>type guessing ";
  342.                     print_r($e_types);
  343.                     echo "<hr>";
  344.                 }else{
  345.                     echo "<br>no type guessing $have_et ";
  346.                     print_r($e_types);
  347.  
  348.                 }
  349.  
  350.                 if($item->siteID==3)
  351.                     $e_types[] = 12;
  352.                 if($item->siteID==7)
  353.                     $e_types[] = 35;
  354.                 if($item->siteID==13)
  355.                     $e_types[] = 35;
  356.                 if($item->siteID==16 OR $item->siteID==22){
  357.                     $e_types[] = 12;
  358.                     $e_types[] = 39;
  359.                     //$e_types[] = 43;
  360.                 }
  361.                 if($item->siteID==17)
  362.                     $e_types[] = 11;
  363.                 if($item->siteID==18){
  364.                     $e_types[] = 43;
  365.                     $e_types[] = 12;
  366.                 }
  367.                 if($item->siteID==21){
  368.                     $e_types[] = 62;
  369.                 }
  370.                 if(!$e_types AND $item->siteID==54){
  371.                     $e_types[] = 9;
  372.                 }
  373.                 if($item->siteID==23){
  374.                     //$e_types[] = 15;
  375.                 }
  376.  
  377.             }
  378.             if(!is_array($e_types))
  379.                 $e_types[] = 15;
  380.             $e_types = array_unique($e_types);
  381.             $etype[eventID] = $eventID;
  382.             while( list($_,$val) = each($e_types) ){
  383.                 $etype[typeID] = $val;
  384.                 if(insert_array('event_eventtype',$etype,'0','1')){
  385.                     echo $val;
  386.                     echo mysql_error();
  387.                     $typ++;
  388.                 }
  389.             }
  390.             $return->mssg .= ",types($typ)";
  391.             // STORE PRICE
  392.             if(is_numeric($item->price)){
  393.                 $price[price] = $item->price;
  394.                 $price[type] = 0;
  395.                 $price[eventID] = $eventID;
  396.                 if(insert_array('eventprice',$price,'0','0'))
  397.                     $return->mssg .= ",price";
  398.             }
  399.             // GET IMAGE
  400.             if($item->image_url!=''){
  401.                 if(get_image($eventID,$item->image_url,$item->title,'event',$item->image_credits))
  402.                     $return->mssg .= ",image";
  403.             }
  404.             // GET&INSERT TIMES
  405.             $time_list = mysql_query("SELECT * FROM {$db}.import_times WHERE import_eventID='$ID'");
  406.             while($time = mysql_fetch_object($time_list)){
  407.                 $times[eventID] = $eventID;
  408.                 $venue_timeID = mysql_fetch_row(mysql_query("SELECT venueID FROM {$db}.import_data WHERE ID='$time->import_dataID'"));
  409.                 if($venue_timeID[0]>0){
  410.                     $times[venueID] = $venue_timeID[0];
  411.                     $times[eventID] = $eventID;
  412.                     $times[period_from] = $time->period_from;
  413.                     $tmpX = explode(" ",$time->period_from);
  414.                     if($tmpX[1]== '00:00:00'){
  415.                         $return->mssg .= "<br /><b><span style='color:orange;'>WARNING: Event starts at 00:00!</span></b>";
  416.                     }
  417.                     $times[period_to] = $time->period_to;
  418.                     $times[venue_spec] = $time->notes;
  419.                     if($event[nature]=='UNIQUE'){
  420.                         $times[fixed] = 'N';
  421.                     }elseif($event[nature]=='FIXED'){
  422.                         $times[fixed] = 'Y';
  423.                         $times[weekday] = $time->weekday;
  424.                         $times[open_from] = $time->open_from;
  425.                         $times[open_to] = $time->open_to;
  426.                     }
  427.                     if(!preg_match("~00:00:00~",$time->venue_open))
  428.                         $times[special] = "zaal open ".substr($time->venue_open,0,5);
  429.                     $times[userID] = $auth_userID;
  430.                     if($timesID = insert_array('times',$times,'1','1')){
  431.                         if($event[nature]=='FIXED'){
  432.                             reset($times);
  433.                             $times[eventID] = '0';
  434.                             $timesID2 = insert_array('times',$times,'1','1');
  435.                         }
  436.                         $tms++;
  437.                         if($timesprices = mysql_query("SELECT * FROM {$db}.import_timesprice WHERE timesID='$time->ID'")){
  438.                             while($timeprice = mysql_fetch_object($timesprices)){
  439.                                 if($reg != '1'){
  440.                                     $import_timesprice[type] = '0';
  441.                                     $reg = 1;
  442.                                 }else   $import_timesprice[type] = '1';
  443.                                 $import_timesprice[price] = $timeprice->price;
  444.                                 $import_timesprice[comment] = $timeprice->comment;
  445.                                 $import_timesprice[timesID] = $timesID;
  446.                                 insert_array('timesprice',$import_timesprice,'0','1');
  447.                                 unset($import_timesprice);
  448.                             }
  449.                         }
  450.                         //STORE TICKETS
  451.                         matchImportSalespoint($time->ID,$timesID);
  452.                     }
  453.                 }
  454.                 unset($times,$query,$timesID);
  455.                 unset($timesID,$reg);
  456.             }
  457.             if($tms>0)
  458.                 $return->mssg .= ",times($tms)";
  459.             mysql_query("UPDATE {$db}.import_event SET eventID='$eventID' WHERE ID='$ID'");
  460.         }else{
  461.             $return->mssg = "ERROR..while inserting EVENT!";
  462.         }
  463.         $return->title = @$item->title;
  464.         $return->ID = @$eventID;
  465.         return $return;
  466.     }
  467. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement