Location: PHPKode > scripts > Playbill > playbill.php
<?
 class playbill {

  /*
   category - íàçâàíèå êàòåãîðèè (òåàòð, êèíîòåàòð, âûñòàâî÷íûé çàë)
   item - íàçâàíèå îáúåêòà êóëüòóðû (êèíîòåàòð "Ðîññèÿ", Òåàòð Êóêîë)
   event - íàçâàíèå ñîáûòèÿ (ñåàíñ ôèëüìà, âûñòàâêà, ñïåêòàêëü)
  */

  var $Error;

  function category ($category_id) {
   $sql="SELECT * FROM afisha_categories WHERE id=".$category_id;
   if ($row=mysql_fetch_array(mysql_query($sql))) {
    return $row["name"];
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function category_add ($name) {
   if ($name=="") return 0;
   $sql="INSERT INTO afisha_categories (name) VALUES ('$name')";
   if(mysql_query($sql)) {
    return 1;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function category_list () {
   $sql="SELECT * FROM afisha_categories";
   if ($res=mysql_query($sql)) {
    $arr=array();
    while ($row=mysql_fetch_array($res)) {
     $arr[]=$row["name"];
    }
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function item_add ($category_id, $item, $desc) {
   if ($category_id=="" || $item=="") return 0;
   $sql="INSERT INTO afisha_items (category_id, item, desc1) VALUES ($category_id, \"$item\", \"$desc\")";
   echo $sql."<br>";
   if ($res=mysql_query($sql)) {
    return 1;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function item_list ($category_id) {
   $sql="SELECT item, id, logo FROM afisha_items WHERE category_id=".$category_id;
   if ($res=mysql_query($sql)) {
    $arr=array();
    $i=0;
    while ($row=mysql_fetch_array($res)) {
     $arr[$i]["item"]=$row["item"];
     $arr[$i]["id"]=$row["id"];
     $arr[$i]["logo"]=$row["logo"];
     $i++;
    }
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function item ($item_id) {
   $sql="SELECT * FROM afisha_items WHERE id=".$item_id;
   if ($res=mysql_query($sql)) {
    $arr=array();
    $row=mysql_fetch_array($res);
    $arr["category_id"]=$row["category_id"];
    $arr["item"]=$row["item"];
    $arr["desc"]=nl2br($row["desc1"]);
    $arr["logo"]=$row["logo"];
    $sql="SELECT * FROM afisha_categories WHERE id=".$row["category_id"];
    $row=mysql_fetch_array(mysql_query($sql));
    $arr["category"]=$row["name"];
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event_add ($item_id, $name, $day_start, $day_end, $time, $desc, $days_week) {
   if ($item_id=="" || $name=="") return 0;
   if ($time!="") {
    $stime=serialize($time);
   }
   else {
    $stime=$time;
   }
   if ($days_week!="") {
    $days_week=serialize($days_week);
   }
   $sql="INSERT INTO afisha_event (item_id, name, day_start, day_end, time, desc1, days_week) VALUES ($item_id, '$name', '$day_start', '$day_end', '$stime', '$desc', '$days_week')";
   echo $sql."<br>";
   if ($res=mysql_query($sql)) {
    return 1;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event_list ($item_id) {
   $this->Error="";
   $arrt=$this->item($item_id);
   $sql="SELECT * FROM afisha_event WHERE item_id=$item_id ORDER BY day_start_mt, id";
   if ($res=mysql_query($sql)) {
    $arr=array();
    $i=0;
    while ($row=mysql_fetch_array($res)) {
     $arr_time=unserialize($row["time"]);
     if ($row["day_start"]==$row["day_end"] && $row["day_start"]!="") {
      ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_start"],$ds);
      ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_end"],$de);
      if (mktime(0,0,0,$ds[2],$ds[1],$ds[3])>mktime(0,0,0)) {
       // Äåíü åùå íå íàñòóïèë
       $i++;
       $arr[$i]["id"]=$row["id"];
       $arr[$i]["name"]=$row["name"];
       $arr[$i]["day_start"]=$row["day_start"];
       $arr[$i]["day_end"]=$row["day_end"];
       for ($j=1;$j<=count($arr_time);$j++) {
        $arr[$i]["time"][]=$arr_time[$j];
       }
      }
      elseif (mktime(0,0,0,$ds[2],$ds[1],$ds[3])==mktime(0,0,0)) {
       // Ñåãîäíÿ
       $cnt=0;
       for ($j=1;$j<=count($arr_time);$j++) {
        ereg("([0-9]{2}):([0-9]{2})",$arr_time[$j],$at);
        if (mktime($at[1],$at[2],0,$ds[2],$ds[1],$ds[3])>mktime()) {
         $cnt++;
        }
       }
       if ($cnt!=0) {
        $i++;
        $arr[$i]["id"]=$row["id"];
        $arr[$i]["name"]=$row["name"];
        $arr[$i]["day_start"]=$row["day_start"];
        $arr[$i]["day_end"]=$row["day_end"];
        for ($j=1;$j<=count($arr_time);$j++) {
         ereg("([0-9]{2}):([0-9]{2})",$arr_time[$j],$at);
         if (mktime($at[1],$at[2],0,$ds[2],$ds[1],$ds[3])>mktime()) {
          $arr[$i]["time"][]=$at[1].".".$at[2];
         }
        }
       }
      }
      elseif ($row["days_week"]!="" && $row["days_week"]!="a:1:{i:1;s:0:\"\";}") {
       $i++;
       $arr[$i]["id"]=$row["id"];
       $arr[$i]["name"]=$row["name"];
       $arr[$i]["days_week"]=unserialize($row["days_week"]);
      }
     }
     else {
      $ds="";
      $de="";
      if ($row["day_start"]!="") {
       ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_start"],$ds);
      }
      if ($row["day_end"]!="") {
       ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_end"],$de);
      }

      if ($ds!="") {
        if ($de!="") {
         if (mktime(0,0,0,$de[2],$de[1],$de[3])>=mktime(0,0,0)) {
          $flag=1;
         }
        }
        else {
         $flag=1;
        }
      }
      elseif ($de!="") {
       if (mktime(0,0,0,$de[2],$de[1],$de[3])>=mktime(0,0,0)) {
        $flag=1;
       }
      }
      else {
       $flag=1;
      }

      if ($flag==1) {
       $i++;
       $arr[$i]["id"]=$row["id"];
       $arr[$i]["name"]=$row["name"];
       $arr[$i]["day_start"]=$row["day_start"];
       $arr[$i]["day_end"]=$row["day_end"];
       if ($row["days_week"]!="" && $row["days_week"]!="a:1:{i:1;s:0:\"\";}") {
        $arr[$i]["days_week"]=unserialize($row["days_week"]);
       }
      }
     }
     $flag=0;
    }
    $arr["item_name"]=$arrt["item"];
    $arr["cat_name"]=$arrt["category"];
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event ($event_id) {
   $sql="SELECT * FROM afisha_event WHERE id=".$event_id;
   if ($res=mysql_query($sql)) {
    $arr=array();
    $row=mysql_fetch_array($res);
    $arr["item_id"]=$row["item_id"];
    $arr["name"]=$row["name"];
    $arr["day_start"]=$row["day_start"];
    $arr["day_end"]=$row["day_end"];
    $arr["time"]=unserialize($row["time"]);
    $arr["desc"]=nl2br($row["desc1"]);
    $arr["desc_mari"]=nl2br($row["desc_mari"]);
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function item_title ($item) {
   $sql="SELECT * FROM afisha_items WHERE id=".$item;
   if ($res=mysql_query($sql)) {
    $row=mysql_fetch_array($res);
    return $row["item"];
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event_title ($event) {
   $arr=array();
   $sql="SELECT * FROM afisha_event WHERE id=".$event;
   if ($res=mysql_query($sql)) {
    $row=mysql_fetch_array($res);
    $arr["event"]=$row["name"];
    $sql="SELECT * FROM afisha_items WHERE id=".$row["item_id"];
    if ($res=mysql_query($sql)) {
     $row=mysql_fetch_array($res);
     $arr["item"]=$row["item"];
     $sql="SELECT * FROM afisha_categories WHERE id=".$row["category_id"];
     $row=mysql_fetch_array(mysql_query($sql));
     $arr["category"]=$row["name"];
     return $arr;
    }
    else {
     $this->Error=mysql_error();
     return 0;
    }
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event_today () {
   $day=date("d");
   $month=date("m");
   $year=date("Y");
   $date=$day.".".$month.".".$year;
   $i=0;
   $sql="SELECT * FROM afisha_event ORDER BY day_start_mt";
   if ($res=mysql_query($sql)) {
    $arr=array();
    while ($row=mysql_fetch_array($res)) {
     ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_start"],$ds);
     ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_end"],$de);
     if (mktime(0,0,0,$ds[2],$ds[1],$ds[3])<=mktime(0,0,0) && mktime(0,0,0,$de[2],$de[1],$de[3])>=mktime(0,0,0)) {
      $arr[$i]["id"]=$row["id"];
      $arr[$i]["name"]=$row["name"];
      $arr[$i]["time"]=$row["time"];
      $arr[$i]["date"]=$date;
      $i++;
     }
    }
    return $arr;
   }
   else {
    $this->Error=mysql_error();
    return 0;
   }
  }

  function event_week () {
   $time_now=mktime(0,0,0);
   $arr=array();
   for ($i=0;$i<=6;$i++) {
    $j=0;
    $sql="SELECT * FROM afisha_event ORDER BY item_id";
    if ($res=mysql_query($sql)) {
     $arrt=array();
     while ($row=mysql_fetch_array($res)) {
      $day_week_flag=1;
      if ($row["day_start"]=="") {
       $row["day_start"]=date("d.m.Y");
      }
      if ($row["day_end"]=="") {
       $row["day_end"]=date("d.m.Y",$time_now+$i*24*60*60);
      }
      if ($row["days_week"]!="") {
       $days_week=unserialize($row["days_week"]);
       $day_week_flag=0;
       foreach ($days_week as $a=>$b) {
        if (date("w",$time_now+$i*24*60*60)==$a) {
         $day_week_flag=1;
        }
       }
      }
      ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_start"],$ds);
      ereg("([0-9]{2}).([0-9]{2}).([0-9]{4})",$row["day_end"],$de);
      if (mktime(0,0,0,$ds[2],$ds[1],$ds[3])<=($time_now+$i*24*60*60) && mktime(0,0,0,$de[2],$de[1],$de[3])>=($time_now+$i*24*60*60) && $day_week_flag==1) {
       $arrt[$j]["id"]=$row["id"];
       $arrt[$j]["name"]=$row["name"];
       $arrt[$j]["desc"]=$row["desc1"];
       if ($row["time"]!="a:1:{i:1;s:0:\"\";}") {
        $arrt[$j]["time"]=unserialize($row["time"]);
       }
       else {
        $arrt[$j]["time"]="";
       }
       $sql1="SELECT * FROM afisha_items WHERE id=".$row["item_id"];
       $row1=mysql_fetch_array(mysql_query($sql1));
       $arrt[$j]["item"]=$row1["item"];
       $j++;
      }
     }
     $arr[$i]=$arrt;
    }
    else {
     $this->Error=mysql_error();
     return 0;
    }
   }
   return $arr;
  }
 }
?>
Return current item: Playbill