Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function insert_array($table,$pairs,$getID='1',$debug='1'){
- global $db;
- if($debug=='1') $o .= $table;
- if(is_array($pairs)){
- while(list($key,$value)=each($pairs)){
- $pair[] = " `$key` = '".@mysql_real_escape_string($value)."'";
- }
- $set = implode(',',$pair);
- $query = "INSERT INTO {$db}.`$table` SET $set";
- if(@mysql_query($query)){
- if($getID=='1'){
- if($ID = @mysql_insert_id()){
- $o .= "...OK($ID)\n";
- if($debug=='1') echo $o;
- return $ID;
- }else{
- $o .= "...OK(noID!)\n";
- }
- }else{
- $o .= "...OK\n";
- if($debug=='1') echo $o;
- return 1;
- }
- }else{
- $o .= "...INSERT ERROR\n";
- }
- }else{
- $o .= "...wrong PAIRS!\n";
- }
- if($debug=='1') echo $o;
- }
- function input_actSoccer($act,$count,$title=''){
- global $db;
- // trims
- if(preg_match("~e\.a\.$~i",$act)) $act = preg_replace("~e\.a\.$~i","",$act);
- elseif(preg_match("~e\.a$~i",$act)) $act = preg_replace("~e\.a$~i","",$act);
- $out->title = trim($act);
- if(stristr($act,"(") AND stristr($act,")")){
- $tmp = explode("(",$act);
- $tmptit = $tmp[0];
- $tmp = explode(")",$tmp[1]);
- $tmp = dbformat($tmp[0]);
- // instruments
- if($instrument = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.instrument WHERE name LIKE '$tmp' OR name_en LIKE '$tmp'"))){
- $out->instrumentID = $instrument[0];
- $out->title = trim($tmptit);
- $out->element_table = 'person';
- }
- // professions
- if($tmp == 'zang' OR $tmp == 'sopraan' OR $tmp == 'bariton'){
- $out->persontypeID = 8;
- //$out->title = trim($tmptit);
- $out->element_table = 'person';
- }
- }
- // type gues
- if(!$out->element_table){
- if(preg_match("~^dj~i",$act) AND stristr($act,"dj ")){
- $out->element_table = 'person';
- $out->persontypeID = 13;
- }elseif(strstr($act,"&") OR stristr($act," orchest") OR stristr($act," duo") OR stristr($act," duet")
- OR stristr($act," trio") OR stristr($act," quartet") OR stristr($act," kwartet") OR stristr($act," quintet")
- OR stristr($act," sextet") OR stristr($act," orkest") OR stristr($act,"group")
- OR stristr($act,"band") OR stristr($act,"groep") OR stristr($act,"ensemble")
- OR stristr($act,"philharmon") OR stristr($act,"filharmon") OR stristr($act,"circus")
- ){
- $out->element_table = 'group';
- }
- }
- if(strstr($out->title,"+ support")){
- $out->title = trim(str_replace("+ support","",$out->title));
- $out->support = 'W';
- }else{
- $out->support = 'N';
- }
- return $out;
- }
- function get_types($array,$table='eventtype',$debug='0'){
- global $db;
- $items = mysql_query("SELECT * FROM {$db}.$table");
- while($item = mysql_fetch_object($items)){
- reset($array);
- while(list($_,$str) = each($array)){
- if($debug=='1') echo '<br>procesing '.$item->name." against $str";
- if( stristr($item->name,$str) OR stristr($item->name_en,$str) ){
- $return[] = $item->ID;
- }
- if(strlen($item->keyw)>0){
- $keyw = explode(",",$item->keyw);
- //echo "..in keyw..";
- while(list($_,$word) = each($keyw)){
- if(stristr($word,$str) OR stristr($str,$word)){
- $return[] = $item->ID;
- }
- }
- }
- if($debug=='1')
- echo ', found:'.count($return);
- }
- }
- if(is_array($return))
- return array_unique($return);
- }
- function get_image1($ID,$url,$title,$table='venue',$credits=''){
- global $db,$auth_userID;
- $url = str_replace(" ","%20",$url);
- set_time_limit(120);
- $info = getimagesize($url);
- switch($info[2]) {
- case 1: $itype = "image/gif"; break;
- case 2: $itype = "image/jpeg";break;
- case 3: $itype = "image/png"; break;
- case 4: $itype = "application/x-shockwave-flash";break;
- }
- if($itype AND $info[0] > 20){
- $check = mysql_num_rows(mysql_query("SELECT ID FROM {$db}.the_image WHERE URL = '$url' AND width = '{$info[0]}' AND height = '{$info[1]}'"));
- if($check > 0){
- // do nothing
- }elseif($f = fopen($url,"rb")){
- $content = base64_encode(implode('',file($url)));
- fclose($f);
- $title = dbformat($title);
- $desc = dbformat($desc);
- $credits = dbformat($credits);
- mysql_query("INSERT INTO {$db}.the_image SET
- title = '$title',
- type = '$itype',
- width = '{$info[0]}',
- height = '{$info[1]}',
- content = '$content',
- description = '$desc',
- URL = '$url',
- credits = '$credits',
- userID = '$auth_userID'");
- sleep(1);
- $imageID = mysql_insert_id();
- if ($imageID>0){
- mysql_query("INSERT INTO {$db}.image_link SET
- imageID = '$imageID',
- elementID = '$ID',
- element_table = '$table',
- medium = 'PC'");
- return 1;
- }
- }
- }
- }
- function matchImportSalespoint($import_timesID,$agendaID){
- global $db,$auth_userID;
- //echo "tryin $import_timesID $agendaID<br>";
- if($import_timesID > 0 AND $agendaID > 0){
- $salespoint = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.import_salespoint WHERE element_table='import_times' AND elementID='$import_timesID'"));
- $agenda = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.times WHERE ID='$agendaID'"));
- if($salespoint->ID>0 AND $agenda->ID>0){
- //echo "found<br>";
- unset($description);
- $event = new event($agenda->eventID);
- $venue = new venue($agenda->venueID);
- $place = new municipal($venue->municipalID);
- $description[] = timestamp2time($agenda->period_from);
- $description[] = $venue->name." - ".$place->name;
- $description = implode(", ",$description);
- if($salespoint->description!='' AND strip_tags($salespoint->description) == $salespoint->description){
- $description .= ", ".$salespoint->description;
- }
- $description = dbformat($description);
- $query = "INSERT INTO {$db}.salespoint SET element_table='times', elementID='$agendaID', vendorID='$salespoint->vendorID', vendorItemID='$salespoint->vendorItemID', ".
- "URL='{$salespoint->URL}', price='{$salespoint->price}', vendorItemImageURL='{$salespoint->vendorItemImageURL}', ".
- "userID='{$auth_userID}', title='$salespoint->title', description='$description'";
- if(mysql_query($query)){
- return true;
- }else{
- echo mysql_error();
- }
- }
- }
- }
- function add_event($ID,$debug='1'){
- global $db,$site,$auth_userID;
- if($item=mysql_fetch_object(mysql_query("SELECT * FROM {$db}.import_event WHERE ID='$ID'"))){
- $event[title] = $item->title;
- $event[subtitle] = $item->subtitle;
- $event[nature] = $item->nature;
- $event[type_spec] = $item->type_spec;
- $event[description] = str_replace("<br />","\n",$item->description);
- if(strlen(trim($item->info))>0){
- $event[temp_desc] .= "\n".$item->info;
- }
- $event[homepage] = $item->url;
- $event[userID] = $auth_userID;
- // TRY TO INSERT FROM ARRAY
- if($eventID = insert_array('event',$event,'1','0')){
- $return->mssg = "OK event";
- $return->nature = $item->nature;
- // check word lenght
- if(strlen($event[type_spec])>17){
- $tmp = explode(" ",$event[type_spec]);
- while(list($_,$tmp1)=each($tmp)){
- if(strlen(trim($tmp1))>17){
- $type_spec_error = 1;
- }
- }
- if($type_spec_error){
- $return->mssg .= "<br /><b><span style='color:orange;'>WARNING: Type spec word(s) too long!</span></b>";
- }
- }
- // store act(s)
- $act = mysql_real_escape_string($item->act);
- if(strlen($act)>0){
- $tmp = explode(",",$act);
- $actcount = count($tmp);
- while(list($_,$tmp1)=each($tmp)){
- unset($actcheck);
- $tmp1obj = input_actSoccer(trim($tmp1),$actcount);
- $tmp1 = $tmp1obj->title;
- if(!($actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE elementID > 0 AND title LIKE '$tmp1' LIMIT 1")))){
- if(!($actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE elementID > 0 AND title LIKE '$tmp1%' LIMIT 1"))))
- $actcheck = mysql_fetch_object(mysql_query("SELECT * FROM {$db}.event_details WHERE title LIKE '$tmp1' LIMIT 1"));
- }
- if(!($actcheck->elementID > 0)){
- if($tmp1obj->element_table == 'person'){
- if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.person WHERE artname LIKE '$tmp1' ORDER BY checked DESC"))){
- $actcheck->elementID = $dbActMatch[0];
- }elseif(mysql_query("INSERT INTO {$db}.person SET artname = '$tmp1', userID = '$auth_userID'")){
- $actcheck->elementID = mysql_insert_id();
- }
- echo mysql_error();
- $actcheck->relationID = 1;
- $actcheck->element_table = 'person';
- }elseif($tmp1obj->element_table == 'group'){
- if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.`group` WHERE title LIKE '$tmp1' ORDER BY checked DESC"))){
- $actcheck->elementID = $dbActMatch[0];
- }elseif(mysql_query("INSERT INTO {$db}.`group` SET title = '$tmp1', userID = '$auth_userID'")){
- $actcheck->elementID = mysql_insert_id();
- }
- echo mysql_error();
- $actcheck->relationID = 1;
- $actcheck->element_table = 'group';
- }else{
- if($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.person WHERE artname LIKE '$tmp1' ORDER BY checked DESC"))){
- $actcheck->elementID = $dbActMatch[0];
- $actcheck->element_table = 'person';
- }elseif($dbActMatch = mysql_fetch_row(mysql_query("SELECT ID FROM {$db}.`group` WHERE title LIKE '$tmp1' ORDER BY checked DESC"))){
- $actcheck->elementID = $dbActMatch[0];
- $actcheck->element_table = 'group';
- }
- echo mysql_error();
- if($actcheck->elementID > 0){
- $actcheck->relationID = 1;
- }
- }
- }
- if($actcheck->elementID > 0){
- if(stristr($event[title]," + support")){
- //$return->mssg .= "<br /><b><span style='color:orange;'>WARNING: "+ support" situation, event renamed!</span></b>";
- $newEventTitle = dbformat(str_replace(" + support","",$event[title]));
- mysql_query("UPDATE {$db}.event SET title = '$newEventTitle' WHERE ID = '$eventID'");
- }
- mysql_query("INSERT INTO {$db}.event_details SET title='$tmp1', eventID = '$eventID',
- relationID='$actcheck->relationID', elementID='$actcheck->elementID',
- element_table='$actcheck->element_table', instrumentID='$tmp1obj->instrumentID', persontypeID='$tmp1obj->persontypeID', support = '$actcheck->support'");
- echo mysql_error();
- if($tmp1obj->instrumentID > 0 AND $actcheck->element_table == 'person'){
- if(!(mysql_num_rows(mysql_query("SELECT * FROM {$db}.person_instrument WHERE personID='$actcheck->elementID' AND
- instrumentID = '$tmp1obj->instrumentID'"))>0)){
- mysql_query("INSERT INTO {$db}.person_instrument SET personID='$actcheck->elementID', instrumentID = '$tmp1obj->instrumentID'");
- echo mysql_error();
- }
- }
- if($tmp1obj->persontypeID > 0 AND $actcheck->element_table == 'person'){
- if(!(mysql_num_rows(mysql_query("SELECT * FROM {$db}.person_persontype WHERE personID='$actcheck->elementID' AND
- typeID = '$tmp1obj->persontypeID'"))>0)){
- mysql_query("INSERT INTO {$db}.person_persontype SET personID='$actcheck->elementID', typeID = '$tmp1obj->persontypeID'");
- echo mysql_error();
- }
- }
- $has_atc++;
- }else{
- if(stristr($event[title]," + support")){
- //$return->mssg .= "<br /><b><span style='color:orange;'>WARNING: "+ support" situation, event renamed!</span></b>";
- //$newEventTitle = dbformat(str_replace(" + support","",$event[title]));
- //mysql_query("UPDATE event SET title = '$newEventTitle' WHERE ID = '$eventID'");
- }
- mysql_query("INSERT INTO {$db}.event_details SET title='$tmp1', eventID = '$eventID', relationID = '1', support = '$actcheck->support'");
- echo mysql_error();
- $has_atc++;
- }
- echo mysql_error();
- }
- }
- if($has_atc > 0){
- $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>";
- }
- // STORE EVENT TYPES
- if($item->siteID=='14'){
- $mtypes = mysql_query("SELECT * FROM {$db}.eventtype");
- while ($mtype = (mysql_fetch_object($mtypes))){
- $b = explode(",",$mtype->onstageIDs);
- while(list($_,$ostID) = each($b)){
- if($item->onstage_typeID==$ostID){
- $e_types[] = $mtype->ID;
- }
- //$bridge[$ostID] = $mtype->ID;
- }
- }
- }else{
- if($itypes = mysql_query("SELECT * FROM {$db}.import_eventtype WHERE import_eventID = '$ID'")){
- while($itype = mysql_fetch_object($itypes)){
- if($itype->eventtypeID > 0){
- $e_types[] = $itype->eventtypeID;
- $have_et = 1;
- echo "<br>type imported";
- }
- }
- }
- if(!is_array($e_types) AND !$have_et){
- $gues_types[] = $item->type_spec;
- $e_types = get_types($gues_types,'eventtype','0');
- echo "<br>type guessing ";
- print_r($e_types);
- echo "<hr>";
- }else{
- echo "<br>no type guessing $have_et ";
- print_r($e_types);
- }
- if($item->siteID==3)
- $e_types[] = 12;
- if($item->siteID==7)
- $e_types[] = 35;
- if($item->siteID==13)
- $e_types[] = 35;
- if($item->siteID==16 OR $item->siteID==22){
- $e_types[] = 12;
- $e_types[] = 39;
- //$e_types[] = 43;
- }
- if($item->siteID==17)
- $e_types[] = 11;
- if($item->siteID==18){
- $e_types[] = 43;
- $e_types[] = 12;
- }
- if($item->siteID==21){
- $e_types[] = 62;
- }
- if(!$e_types AND $item->siteID==54){
- $e_types[] = 9;
- }
- if($item->siteID==23){
- //$e_types[] = 15;
- }
- }
- if(!is_array($e_types))
- $e_types[] = 15;
- $e_types = array_unique($e_types);
- $etype[eventID] = $eventID;
- while( list($_,$val) = each($e_types) ){
- $etype[typeID] = $val;
- if(insert_array('event_eventtype',$etype,'0','1')){
- echo $val;
- echo mysql_error();
- $typ++;
- }
- }
- $return->mssg .= ",types($typ)";
- // STORE PRICE
- if(is_numeric($item->price)){
- $price[price] = $item->price;
- $price[type] = 0;
- $price[eventID] = $eventID;
- if(insert_array('eventprice',$price,'0','0'))
- $return->mssg .= ",price";
- }
- // GET IMAGE
- if($item->image_url!=''){
- if(get_image($eventID,$item->image_url,$item->title,'event',$item->image_credits))
- $return->mssg .= ",image";
- }
- // GET&INSERT TIMES
- $time_list = mysql_query("SELECT * FROM {$db}.import_times WHERE import_eventID='$ID'");
- while($time = mysql_fetch_object($time_list)){
- $times[eventID] = $eventID;
- $venue_timeID = mysql_fetch_row(mysql_query("SELECT venueID FROM {$db}.import_data WHERE ID='$time->import_dataID'"));
- if($venue_timeID[0]>0){
- $times[venueID] = $venue_timeID[0];
- $times[eventID] = $eventID;
- $times[period_from] = $time->period_from;
- $tmpX = explode(" ",$time->period_from);
- if($tmpX[1]== '00:00:00'){
- $return->mssg .= "<br /><b><span style='color:orange;'>WARNING: Event starts at 00:00!</span></b>";
- }
- $times[period_to] = $time->period_to;
- $times[venue_spec] = $time->notes;
- if($event[nature]=='UNIQUE'){
- $times[fixed] = 'N';
- }elseif($event[nature]=='FIXED'){
- $times[fixed] = 'Y';
- $times[weekday] = $time->weekday;
- $times[open_from] = $time->open_from;
- $times[open_to] = $time->open_to;
- }
- if(!preg_match("~00:00:00~",$time->venue_open))
- $times[special] = "zaal open ".substr($time->venue_open,0,5);
- $times[userID] = $auth_userID;
- if($timesID = insert_array('times',$times,'1','1')){
- if($event[nature]=='FIXED'){
- reset($times);
- $times[eventID] = '0';
- $timesID2 = insert_array('times',$times,'1','1');
- }
- $tms++;
- if($timesprices = mysql_query("SELECT * FROM {$db}.import_timesprice WHERE timesID='$time->ID'")){
- while($timeprice = mysql_fetch_object($timesprices)){
- if($reg != '1'){
- $import_timesprice[type] = '0';
- $reg = 1;
- }else $import_timesprice[type] = '1';
- $import_timesprice[price] = $timeprice->price;
- $import_timesprice[comment] = $timeprice->comment;
- $import_timesprice[timesID] = $timesID;
- insert_array('timesprice',$import_timesprice,'0','1');
- unset($import_timesprice);
- }
- }
- //STORE TICKETS
- matchImportSalespoint($time->ID,$timesID);
- }
- }
- unset($times,$query,$timesID);
- unset($timesID,$reg);
- }
- if($tms>0)
- $return->mssg .= ",times($tms)";
- mysql_query("UPDATE {$db}.import_event SET eventID='$eventID' WHERE ID='$ID'");
- }else{
- $return->mssg = "ERROR..while inserting EVENT!";
- }
- $return->title = @$item->title;
- $return->ID = @$eventID;
- return $return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement