public function beforeValidate() { if (parent::beforeValidate()) { $cams = array_map('trim', explode(',', $this->hcams)); $c = count($cams); foreach ($cams as $cam) { $this->camBuff[] = Cams::model()->findByPK(Cams::model()->getRealId($cam)); } $this->camBuff = array_filter($this->camBuff); if (empty($this->camBuff) || count($this->camBuff) != $c) { $this->addError('cams', $c > 1 ? Yii::t('errors', 'One of cam is wrong') : Yii::t('errors', 'There is no such cam')); return false; } if (!is_array($this->emails)) { $emails = array_map('trim', explode(',', $this->emails)); } else { $emails = array_map('trim', $this->emails); } $c = count($emails); $this->emailBuff = Users::model()->findAllByAttributes(array('email' => $emails)); if (empty($this->emailBuff) || count($this->emailBuff) != $c) { $this->addError('emails', $c > 1 ? Yii::t('errors', 'One of user is wrong') : Yii::t('errors', 'There is no such user')); return false; } return true; } return false; }
private function getAvailableCams() { $myCams = Cams::getAvailableCams(); $select_options = array(); foreach ($myCams as $key => $cam) { $select_options[$cam->id] = $cam->name; } return $select_options; }
private function compileCams($cam) { $camName = explode('_', $cam); $camName = $this->double ? Shared::model()->findByPK($camName[1])->cam : Cams::model()->findByPK(Cams::model()->getRealId($camName[1])); if (!$camName) { throw new CHttpException(404, Yii::t('errors', 'There is no such cam')); } $this->buff[$cam] = $camName->getSessionId(); return $camName->name; }
?> /player/js/flowplayer-3.2.13.min.js"></script> <?php // max 16 cams on screen $colors = array(1 => "#FF0000", 2 => "#00FF00", 3 => "#0000FF", 4 => "#000000", 5 => "#FFFF00", 6 => "#FF00FF", 7 => "#00FFFF", 8 => "#080000", 9 => "#000800", 10 => "#000008", 11 => "#800000", 12 => "#008000", 13 => "#000080", 14 => "#008080", 15 => "#800080", 16 => "#808000"); $players = ""; for ($i = 1; $i <= 16; $i++) { eval("\$id=\$model->cam{$i}_id;"); eval("\$x=\$model->cam{$i}_x;"); eval("\$y=\$model->cam{$i}_y;"); eval("\$w=\$model->cam{$i}_w;"); eval("\$h=\$model->cam{$i}_h;"); eval("\$descr=\$model->cam{$i}_descr;"); if ($id && $w > 0 && $h > 0) { $cam = Cams::model()->findByPK($id); $stream = $cam->getSessionId(); $stream_low = $cam->getSessionId(true); if (isset($servers[$cam->server_id])) { $server = $servers[$cam->server_id]; } else { $server = $servers[$cam->server_id] = Servers::model()->findByPK($cam->server_id); } $players .= 'document["MyPlayer' . $i . '"].setSource("rtmp://' . $server->ip . ':' . $server->l_port . '/live/", "' . $stream_low . '", "' . $stream . '");' . "\n"; echo '<div class="cams" id="player' . $i . '" href="' . $id . '" style="background-color:' . $colors[$i] . ';'; echo ' position:absolute;width:' . $w . '%;height:' . $h . '%;left:' . $x . '%;top:' . $y . '%;">'; ?> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%" id="MyPlayer<?php echo "{$i}\""; ?> cam_id=<?php
public static function getAvailableCams() { $id = Yii::app()->user->getId(); $public = array(); $publicAll = Cams::model()->findAllByAttributes(array('is_public' => 1)); $shared = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 0)); foreach ($shared as $key => $value) { if (!isset($value->cam->id)) { $value->delete(); unset($shared[$key]); } } $publicEdited = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 1), array('index' => 'cam_id')); foreach ($publicAll as $cam) { if (isset($publicEdited[$cam->id])) { $public[] = $publicEdited[$cam->id]; } else { $public[] = $cam; } } $myCams = Cams::model()->findAllByAttributes(array('user_id' => $id)); $myPublicCams = $public; $mySharedCams = $shared; $allMyCams = array(); foreach ($myCams as $key => $cam) { $allMyCams[$cam->id] = $cam; } foreach ($myPublicCams as $key => $cam) { if (isset($cam->cam)) { $allMyCams[$cam->id] = $cam->cam; } else { $allMyCams[$cam->id] = $cam; } } foreach ($mySharedCams as $key => $cam) { $allMyCams[$cam->cam_id] = $cam->cam; } return $allMyCams; }
public function actionCams() { $id = Yii::app()->user->getId(); if (isset($_POST['CamsForm']) && !empty($_POST['CamsForm']) && array_sum($_POST['CamsForm']) != 0) { if (isset($_POST['public'])) { foreach ($_POST['CamsForm'] as $key => $cam) { if ($cam) { $key = explode('_', $key); $cam = Cams::model()->findByPK((int) $key[1]); if ($cam) { $cam->is_public = $cam->is_public ? 0 : 1; if ($cam->save()) { Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('admin', 'Cams settings successfully changed'))); } } } } } } $myCams = Cams::model()->findAllByAttributes(array('user_id' => $id)); $public = Cams::model()->findAllByAttributes(array('is_public' => 1)); $criteria = new CDbCriteria(); $criteria->addNotInCondition('id', CHtml::listData($myCams, 'id', 'id')); $criteria->addNotInCondition('id', CHtml::listData($public, 'id', 'id')); $count = Cams::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $pages->applyLimit($criteria); $all = Cams::model()->findAll($criteria); $this->render('cams/index', array('form' => new CamsForm(), 'myCams' => $myCams, 'publicCams' => $public, 'allCams' => $all, 'pages' => $pages)); }