Exemplo n.º 1
0
 function update_day()
 {
     if (!$this->input['channel_id']) {
         $this->errorOutput("未传入频道ID");
     }
     if (!$this->input['dates']) {
         $this->errorOutput("未传入更新日期");
     }
     /*
     $sql = "select r.start_time,r.end_time,r.channel_id,r.week_num,p.item from " . DB_PREFIX . "program_record p left join " . DB_PREFIX . "program_record_relation r on p.id = r.record_id where r.channel_id=" . $this->input['channel_id'] . " and r.week_num=".date('N',strtotime($this->input['dates']));
     		$q = $this->db->query($sql);
     				$record = array();
     		while($r = $this->db->fetch_array($q))
     		{
     			$record[] = $r['start_time'] . '-' . $r['end_time'] . '-' . $r['item'];
     		}
     */
     include_once ROOT_PATH . 'lib/class/live.class.php';
     $obj_live = new live();
     include_once ROOT_PATH . 'lib/class/curl.class.php';
     $this->curl = new curl($this->settings['mms']['record_server']['host'], $this->settings['mms']['record_server']['dir']);
     $arr = array('color' => $this->input['color'], 'checke' => $this->input['checke'], 'start_time' => $this->input['start_time'], 'theme' => $this->input['theme'], 'end_time' => $this->input['end_time'], 'item' => $this->input['item'], 'new' => $this->input['new'], 'plan' => $this->input['plan'], 'plan_source' => $this->input['plan_source'], 'program_source' => $this->input['program_source']);
     foreach ($arr as $key => $value) {
         if (empty($value)) {
             unset($arr[$key]);
         }
     }
     $dates = urldecode($this->input['dates']);
     if (empty($arr)) {
         $sql = "SELECT * FROM " . DB_PREFIX . "program WHERE channel_id = " . $this->input['channel_id'] . " and dates='" . $dates . "'";
         $q = $this->db->query($sql);
         $tmp_record_id = $tmp_space = '';
         while ($row = $this->db->fetch_array($q)) {
             if ($row['record_id']) {
                 $tmp_record_id .= $tmp_space . $row['record_id'];
                 $tmp_space = ',';
             }
         }
         if ($tmp_record_id) {
             $sql = "SELECT * FROM " . DB_PREFIX . "program_record WHERE id IN (" . $tmp_record_id . ")";
             $q = $this->db->query($sql);
             $tmp_record_id_plan = $tmp_record_id_program = 0;
             $space_plan = $space_program = '';
             while ($row = $this->db->fetch_array($q)) {
                 if ($row['plan_id']) {
                     $tmp_record_id_plan .= $space_plan . $row['id'];
                     $space_plan = ',';
                 } else {
                     $tmp_record_id_program .= $space_program . $row['id'];
                     $space_program = ',';
                 }
             }
             if ($tmp_record_id_program) {
                 $obj_live->delete_record($tmp_record_id_program);
             }
             if ($tmp_record_id_plan) {
                 $sql = "UPDATE " . DB_PREFIX . "program_record SET program_id=0 WHERE id IN(" . $tmp_record_id_plan . ")";
                 $this->db->query($sql);
             }
         }
         $sql = "DELETE FROM " . DB_PREFIX . "program WHERE channel_id = " . $this->input['channel_id'] . " and dates='" . $dates . "'";
         $this->db->query($sql);
         $program_plan = $this->getPlan($this->input['channel_id'], $dates);
         $program = array();
         $start = strtotime($dates . " 00:00:00");
         $end = strtotime($dates . " 23:59:59");
         if (empty($program_plan)) {
             $program[] = $this->getInfo($start, strtotime($dates . " 08:00:00"), $dates, $this->input['channel_id'], 1, 0);
             $program[] = $this->getInfo(strtotime($dates . " 08:00:00"), $end, $dates, $this->input['channel_id']);
         } else {
             $com_time = 0;
             foreach ($program_plan as $k => $v) {
                 if (!$com_time && $v['start_time'] > $start) {
                     $program[] = $this->getInfo($start, $v['start_time'], $dates, $this->input['channel_id']);
                 }
                 if ($com_time && $com_time != $v['start_time']) {
                     $program[] = $this->getInfo($com_time, $v['start_time'], $dates, $this->input['channel_id']);
                 }
                 $v['start'] = date("H:i", $v['start_time']);
                 $v['end'] = date("H:i", $v['start_time'] + $v['toff']);
                 if ($v['start_time'] <= TIMENOW) {
                     $v['outdate'] = 1;
                 } else {
                     $v['outdate'] = 0;
                 }
                 $com_time = $v['start_time'] + $v['toff'];
                 $program[] = $v;
             }
             if ($com_time && $com_time < $end) {
                 $program[] = $this->getInfo($com_time, $end, $dates, $this->input['channel_id']);
             }
         }
         //	file_put_contents('../cache/2.php',var_export($program,1));
         $this->addItem($program);
         $this->output();
     }
     $prev_end = 0;
     foreach ($arr['start_time'] as $k => $v) {
         $start_this = strtotime(urldecode($dates . " " . $v));
         $end_this = strtotime(urldecode($dates . " " . $arr['end_time'][$k]));
         if ($start_this >= $end_this) {
             $this->errorOutput($v . '~' . urldecode($arr['end_time'][$k]) . "的开始时间大于等于结束时间");
         }
         if ($prev_end && $prev_end > $start_this) {
             $this->errorOutput($start_this . "的上一个节目的时间有误");
         }
         $prev_end = $end_this;
     }
     $ids = $spa = '';
     foreach ($arr['color'] as $key => $value) {
         $pid = $key;
         if ($arr['checke'][$pid]) {
             $info = array('id' => $pid, 'color' => urldecode($value), 'start_time' => strtotime(urldecode($dates . " " . $arr['start_time'][$key])), 'theme' => rawurldecode($arr['theme'][$key]), 'toff' => strtotime(urldecode($dates . " " . $arr['end_time'][$key])) - strtotime(urldecode($dates . " " . $arr['start_time'][$key])), 'item' => intval($arr['item'][$key]), 'new' => urldecode($arr['new'][$key]), 'plan' => intval($arr['plan'][$key]), 'plan_source' => intval($arr['plan_source'][$key]), 'program_source' => intval($arr['program_source'][$key]));
             if ($info['new']) {
                 $creates = array('channel_id' => $this->input['channel_id'], 'start_time' => $info['start_time'], 'toff' => $info['toff'], 'theme' => rawurldecode($arr['theme'][$key]), 'type_id' => 1, 'weeks' => date("W", $info['start_time']), 'dates' => date("Y-m-d", $info['start_time']), 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip(), 'is_show' => 1);
                 $sql = "INSERT INTO " . DB_PREFIX . "program SET ";
                 $space = "";
                 foreach ($creates as $k => $v) {
                     $sql .= $space . $k . "=" . "'" . $v . "'";
                     $space = ",";
                 }
                 $this->db->query($sql);
                 $info['id'] = $this->db->insert_id();
                 $pid = $info['id'];
                 if ($info['item'] > 0) {
                     $record_create = array('title' => $info['theme'], 'channel_id' => $this->input['channel_id'], 'program_id' => $info['id'], 'start_time' => $info['start_time'], 'toff' => $info['toff'], 'item' => $info['item'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                     if ($record_create['start_time'] < TIMENOW) {
                         $record_create['is_out'] = 1;
                     }
                     if ($info['plan']) {
                         $sql = "SELECT id FROM " . DB_PREFIX . "program_record WHERE plan_id=" . $info['plan'];
                         $tmp_plan_record = $this->db->query_first($sql);
                         if ($info['program_source'] == 2) {
                             $createsql = "INSERT INTO " . DB_PREFIX . "program_record SET ";
                             $space = "";
                             foreach ($record_create as $k => $v) {
                                 $createsql .= $space . $k . "=" . "'" . $v . "'";
                                 $space = ",";
                             }
                             $this->db->query($createsql);
                             $record_id = $this->db->insert_id();
                             $this->insert_relation($record_create['channel_id'], $record_id, $record_create['start_time'], $record_create['toff'], 0);
                             $sql = "UPDATE " . DB_PREFIX . "program SET record_id='" . $record_id . "' WHERE id=" . $info['id'];
                             $this->db->query($sql);
                         } else {
                             if (!empty($tmp_plan_record)) {
                                 $sql = "UPDATE " . DB_PREFIX . "program_record SET program_id=" . $info['id'] . " WHERE plan_id=" . $info['plan'];
                                 $this->db->query($sql);
                                 $sql = "UPDATE " . DB_PREFIX . "program SET record_id='" . $tmp_plan_record['id'] . "' WHERE id=" . $info['id'];
                                 $this->db->query($sql);
                             } else {
                             }
                         }
                     } else {
                         //不是计划,而且有录制,说明肯定创建单天录制
                         $createsql = "INSERT INTO " . DB_PREFIX . "program_record SET ";
                         $space = "";
                         foreach ($record_create as $k => $v) {
                             $createsql .= $space . $k . "=" . "'" . $v . "'";
                             $space = ",";
                         }
                         $this->db->query($createsql);
                         $record_id = $this->db->insert_id();
                         $this->insert_relation($record_create['channel_id'], $record_id, $record_create['start_time'], $record_create['toff'], 0);
                         $sql = "UPDATE " . DB_PREFIX . "program SET record_id='" . $record_id . "' WHERE id=" . $info['id'];
                         $this->db->query($sql);
                     }
                 }
             } else {
                 $sql = "UPDATE " . DB_PREFIX . "program SET color='" . $info['color'] . "',start_time=" . $info['start_time'] . ",theme='" . $info['theme'] . "',toff=" . $info['toff'] . " where id=" . $info['id'];
                 $this->db->query($sql);
                 if ($info['item'] > 0) {
                     $record_create = array('title' => $info['theme'], 'channel_id' => $this->input['channel_id'], 'program_id' => $info['id'], 'start_time' => $info['start_time'], 'toff' => $info['toff'], 'item' => $info['item'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
                     $sql = "SELECT * FROM " . DB_PREFIX . "program_record WHERE program_id=" . $info['id'];
                     $tmp_senc = $this->db->query_first($sql);
                     if (empty($tmp_senc)) {
                         $createsql = "INSERT INTO " . DB_PREFIX . "program_record SET ";
                         $space = "";
                         foreach ($record_create as $k => $v) {
                             $createsql .= $space . $k . "=" . "'" . $v . "'";
                             $space = ",";
                         }
                         $this->db->query($createsql);
                         $record_id = $this->db->insert_id();
                         $this->insert_relation($record_create['channel_id'], $record_id, $record_create['start_time'], $record_create['toff'], 0);
                         $sql = "UPDATE " . DB_PREFIX . "program SET record_id='" . $record_id . "' WHERE id=" . $info['id'];
                         $this->db->query($sql);
                     } else {
                         $record_update = array('title' => $info['theme'], 'start_time' => $info['start_time'], 'toff' => $info['toff'], 'item' => $info['item'], 'update_time' => TIMENOW);
                         $sql = "SELECT id,log_id,conid FROM " . DB_PREFIX . "program_queue WHERE id=" . $tmp_senc['conid'];
                         $sen = $this->db->query_first($sql);
                         if ($sen) {
                             $this->curl->mPostContentType('string');
                             $this->curl->setSubmitType('get');
                             $this->curl->setReturnFormat('json');
                             $this->curl->initPostData();
                             if (!defined('IS_WOZA') || !IS_WOZA) {
                                 $this->curl->addRequestData('action', 'DELETE');
                             } else {
                                 $this->curl->addRequestData('action', 'delete');
                             }
                             $this->curl->addRequestData('id', $sen['conid']);
                             $record_xml = $this->curl->request('');
                             $record_array = xml2Array($record_xml);
                             if ($record_array['result']) {
                                 $sql = "DELETE FROM " . DB_PREFIX . "program_record_log WHERE id IN (" . $sen['log_id'] . ")";
                                 $this->db->query($sql);
                                 $sql = "DELETE FROM " . DB_PREFIX . "program_queue WHERE id=" . $sen['id'];
                                 $this->db->query($sql);
                             }
                         }
                         if (empty($tmp_senc['week_day'])) {
                             if ($record_update['start_time'] <= TIMENOW) {
                                 //相当于重置录制
                                 $record_update['is_out'] = 1;
                             }
                             $updatesql = "UPDATE " . DB_PREFIX . "program_record SET ";
                             $space = "";
                             foreach ($record_update as $k => $v) {
                                 $updatesql .= $space . $k . "=" . "'" . $v . "'";
                                 $space = ",";
                             }
                             $updatesql .= " WHERE program_id=" . $info['id'];
                             $this->db->query($updatesql);
                         } else {
                             if ($record_update['start_time'] <= TIMENOW) {
                                 $week_now = date('N', TIMENOW);
                                 $week_num = unserialize($tmp_senc['week_day']);
                                 if (in_array($week_now, $week_num)) {
                                     $dates = date('Y-m-d', TIMENOW);
                                 }
                                 $i = 0;
                                 $next_day = $next_week_day = 0;
                                 foreach ($week_num as $k => $v) {
                                     if (!$i && $v > $week_now) {
                                         $next_day = $v;
                                         $i = 1;
                                     }
                                     if (!$k) {
                                         $next_week_day = $v;
                                     }
                                 }
                                 if (!$next_day) {
                                     $next_day = $next_week_day;
                                 }
                                 $next_week = $next_day - $week_now > 0 ? $next_day - $week_now : $next_day - $week_now + 7;
                                 $dates = date('Y-m-d', TIMENOW + $next_week * 86400);
                                 $record_update['start_time'] = strtotime($dates . ' ' . date('H:i:s', $tmp_senc['start_time']));
                             }
                             $updatesql = "UPDATE " . DB_PREFIX . "program_record SET ";
                             $space = "";
                             foreach ($record_update as $k => $v) {
                                 $updatesql .= $space . $k . "=" . "'" . $v . "'";
                                 $space = ",";
                             }
                             $updatesql .= " WHERE program_id=" . $info['id'];
                             $this->db->query($updatesql);
                         }
                     }
                 } else {
                     $sql = "SELECT * FROM " . DB_PREFIX . "program_record WHERE program_id=" . $info['id'];
                     $tmp_senc = $this->db->query_first($sql);
                     if (empty($tmp_senc)) {
                         //对录制不做任何操作
                     } else {
                         if ($tmp_senc['plan_id']) {
                             $sql = "UPDATE " . DB_PREFIX . "program_record SET program_id=0 WHERE id=" . $tmp_senc['id'];
                             $this->db->query($sql);
                         } else {
                             $obj_live->delete_record($tmp_senc['id']);
                         }
                         //原本的节目中的录制ID必须更新为0
                         $sql = "UPDATE " . DB_PREFIX . "program SET record_id=0 WHERE id=" . $info['id'];
                         $this->db->query($sql);
                     }
                 }
             }
         }
         $ids .= $spa . $pid;
         $spa = ',';
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "program WHERE channel_id = " . $this->input['channel_id'] . " AND id NOT IN(" . $ids . ") and dates='" . $dates . "'";
     $q = $this->db->query($sql);
     $tmp_record_id = $tmp_space = '';
     while ($row = $this->db->fetch_array($q)) {
         if ($row['record_id']) {
             $tmp_record_id .= $tmp_space . $row['record_id'];
             $tmp_space = ',';
         }
     }
     if ($tmp_record_id) {
         $sql = "SELECT * FROM " . DB_PREFIX . "program_record WHERE id IN (" . $tmp_record_id . ")";
         $q = $this->db->query($sql);
         $tmp_record_id_plan = $tmp_record_id_program = 0;
         $space_plan = $space_program = '';
         while ($row = $this->db->fetch_array($q)) {
             if ($row['plan_id']) {
                 $tmp_record_id_plan .= $space_plan . $row['id'];
                 $space_plan = ',';
             } else {
                 $tmp_record_id_program .= $space_program . $row['id'];
                 $space_program = ',';
             }
         }
         if ($tmp_record_id_program) {
             $obj_live->delete_record($tmp_record_id_program);
         }
         if ($tmp_record_id_plan) {
             $sql = "UPDATE " . DB_PREFIX . "program_record SET program_id=0 WHERE id IN(" . $tmp_record_id_plan . ")";
             $this->db->query($sql);
         }
     }
     $sql = "DELETE FROM " . DB_PREFIX . "program WHERE channel_id = " . $this->input['channel_id'] . " AND id NOT IN(" . $ids . ") and dates='" . $dates . "'";
     $this->db->query($sql);
     $program = $this->get_program($this->input['channel_id'], $dates);
     //	file_put_contents('../cache/1.php',var_export($program,1));
     $this->addItem($program);
     $this->output();
 }
Exemplo n.º 2
0
 public function delete($id)
 {
     if (empty($id)) {
         return false;
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "program_plan WHERE id=" . $id;
     $f = $this->db->query_first($sql);
     if ($f['id']) {
         if ($f['record_id']) {
             include_once ROOT_PATH . 'lib/class/live.class.php';
             $obj_live = new live();
             $obj_live->delete_record($f['record_id']);
         }
         $sql_ = "SELECT * FROM " . DB_PREFIX . "program_plan WHERE id = " . $id;
         $pre_data = $this->db->query_first($sql_);
         $sql = "DELETE FROM " . DB_PREFIX . "program_plan WHERE id=" . $id;
         $r = $this->db->query($sql);
         $sql = "DELETE FROM " . DB_PREFIX . "program_plan_relation WHERE plan_id=" . $id;
         $r = $this->db->query($sql);
         $this->addLogs('delete', $pre_data, '', '', '');
     }
     return $f['channel_id'];
 }