public function ActionVideo_add_to_my_page($id, $mid) { $video_model = new Videos(); if ($video = $video_model->findByPk($mid)) { $video_model->isNewRecord = true; $video_model->id = 0; $video_model->file = $video['file']; $video_model->upload_date = time(); $video_model->user_id = Yii::app()->user->id; $video_model->save(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Videos(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Videos'])) { $model->attributes = $_POST['Videos']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Videos(); if (isset($_POST['Videos'])) { $model->attributes = $_POST['Videos']; $model->created = time(); if ($model->save()) { Yii::app()->user->setFlash('success', translate('Thêm thành công.')); $this->redirect(PIUrl::createUrl('/admin/videos/index')); } } $this->render('create', array('model' => $model)); }
public function postSubirVideo() { $res = ''; $ie = Input::get('ie'); if (isset($_FILES['archivo'])) { $file = $_FILES['archivo']; $name = $file['name']; $tmp_name = $file['tmp_name']; $extension = explode('.', $name); $extension = strtolower(end($extension)); $key = md5(uniqid()); $tmp_file_name = "{$key}.{$extension}"; $tmp_file_path = "../uploads/{$tmp_file_name}"; move_uploaded_file($tmp_name, $tmp_file_path); $videos = new Videos(); $videos->dni = trim(Input::get('dni')); $videos->archivo_original = $name; $videos->archivo = $key; $videos->extension = $extension; $videos->ip = Request::getClientIp(true); $videos->save(); $res = '1'; } else { $res = '0'; } /*if (Agent::isMobile()) return View::make('mensaje.mobile'); if ($ie === '1') { return View::make('mensaje'); } else { return $res; }*/ if (Agent::isMobile()) { return View::make('mensajeMobile'); } else { return View::make('mensaje'); } }
/** * Add new Video * * @return bool */ public function add($name, $desc, $url, $updatedby, $length, $position, $thumb, $schedule_id, $time) { $validator = Validator::make(array('name' => $name, 'desc' => $desc, 'url' => $url, 'updatedby' => $updatedby, 'length' => $length, 'thumb' => $thumb, 'position' => $position, 'time' => $time, 'schedule_id' => $schedule_id), array('name' => array('required', 'min:3'), 'desc' => array(), 'url' => array('required'), 'updatedby' => array('required'), 'length' => array('required'), 'thumb' => array(), 'position' => array('required'), 'time' => array('required'), 'schedule_id' => array('alpha_num', 'required'))); // Validation did not pass if ($validator->fails()) { throw new Exception($validator->messages()); } try { $video = new Videos(); $video->name = $name; $video->desc = $desc; $video->url = $url; $video->length = $length; $video->thumb = $thumb; $video->position = $position; $video->time = $time; $video->updatedby = $updatedby; $video->schedule_id = $schedule_id; $video->save(); return true; } catch (Exception $ex) { return $ex; } }
/** * Lists all models. */ public function actionIndex() { if (isset($_POST['oper']) && $_POST['oper'] == 'edit') { $id = intval($_POST["id"]); $video = Videos::model()->findByPk($id); if ($video) { $error_string= ''; $video->Video_Title =$_POST['Video_Title'] ? $_POST["Video_Title"] : null; $video->Video_Log_Line =$_POST['Video_Log_Line'] ? $_POST["Video_Log_Line"] : null; $video->Video_Desc =$_POST['Video_Desc'] ? $_POST["Video_Desc"] : null; $video->Link_Title =$_POST['Link_Title'] ? $_POST["Link_Title"] : null; $video->Sort_Order =$_POST['Sort_Order'] ? $_POST["Sort_Order"] : null; $video->Video_URL =$_POST['Video_URL'] ? addslashes($_POST['Video_URL']) : null; $video->Video_Password =$_POST['Video_Password'] ? $_POST["Video_Password"] : null; $video->Visibility =$_POST['Visibility'] ? $_POST["Visibility"] : null; if (intval($_POST['Visibility'])==4) { $client_id = intval($_POST['Clients_Client_ID']); $client = Clients::model()->findByPk($client_id); if (!$client) { $error_string = 'Client_ID should be real'; } } if (intval($_POST['Visibility'])==5) { $client_id = intval($_POST['Clients_Client_ID']); $project_id = intval($_POST['Clients_Client_ID']); $project = Projects::model()->findByAttributes(array( 'Project_ID'=>$project_id, 'Client_ID'=>$client_id )); if (!$project) { $error_string = 'There is no project for such Client_ID and Project_ID'; } } $video->Clients_Client_ID =$_POST['Clients_Client_ID'] ? $_POST["Clients_Client_ID"] : null; $video->Project_ID =$_POST['Project_ID'] ? $_POST["Project_ID"] : null; if ($video->validate() && $error_string == '') { $video->save(); echo "video\n"; } else { die($error_string); } } die; } if (isset($_POST['oper']) && $_POST['oper'] == 'add') { // var_dump($_POST);die; $error_string= ''; $video = new Videos(); $video->Video_Title =$_POST['Video_Title']; $video->Video_Log_Line =$_POST['Video_Log_Line']; $video->Video_Desc =$_POST['Video_Desc']; $video->Link_Title =$_POST['Link_Title']; $video->Video_URL =addslashes($_POST['Video_URL']); $video->Video_Password =$_POST['Video_Password']; $video->Sort_Order =$_POST['Sort_Order'] ? $_POST["Sort_Order"] : 1; if (intval($_POST['Visibility'])==4) { $client_id = intval($_POST['Clients_Client_ID']); $client = Clients::model()->findByPk($client_id); if (!$client) { $error_string = 'Client_ID should be real'; } } if (intval($_POST['Visibility'])==5) { $client_id = intval($_POST['Clients_Client_ID']); $project_id = intval($_POST['Clients_Client_ID']); $project = Projects::model()->findByAttributes(array( 'Project_ID'=>$project_id, 'Client_ID'=>$client_id )); if (!$project) { $error_string = 'There is no project for such Client_ID and Project_ID'; } } $video->Visibility =$_POST['Visibility']; $video->Clients_Client_ID =$_POST['Clients_Client_ID']; $video->Project_ID =$_POST['Project_ID']; if ($error_string == '') { $video->save(); } else { die($error_string); } } if (isset($_POST['oper']) && $_POST['oper'] == 'del') { $video_id = intval($_POST["id"]); $video =Videos::model()->findByPk($video_id); if ($video) { $video->delete(); } die; } $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword); mysql_select_db(Yii::app()->params->dbname); mysql_query("SET NAMES 'utf8'"); Yii::import('ext.phpgrid.inc.jqgrid'); // set columns $col = array(); $col["title"] = "Video_ID"; // caption of column $col["name"] = "Video_ID"; $col["dbname"] = "Video_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = false; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = false; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Video_Title"; // caption of column $col["name"] = "Video_Title"; $col["dbname"] = "Video_Title"; // grid column name, same as db field or alias from sql $col["resizable"] = false; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Video_Log_Line"; // caption of column $col["name"] = "Video_Log_Line"; $col["dbname"] = "Video_Log_Line"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Video_Desc"; // caption of column $col["name"] = "Video_Desc"; $col["dbname"] = "Video_Desc"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Link_Title"; // caption of column $col["name"] = "Link_Title"; $col["dbname"] = "Link_Title"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Video_URL"; // caption of column $col["name"] = "Video_URL"; $col["dbname"] = "Video_URL"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Video_Password"; // caption of column $col["name"] = "Video_Password"; $col["dbname"] = "Video_Password"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Sort_Order"; // caption of column $col["name"] = "Sort_Order"; $col["dbname"] = "Sort_Order"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Visibility"; // caption of column $col["name"] = "Visibility"; $col["dbname"] = "Visibility"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Clients_Client_ID"; // caption of column $col["name"] = "Clients_Client_ID"; $col["dbname"] = "Clients_Client_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; // set columns $col = array(); $col["title"] = "Project_ID"; // caption of column $col["name"] = "Project_ID"; $col["dbname"] = "Project_ID"; // grid column name, same as db field or alias from sql $col["resizable"] = true; $col["editable"] = true; // this column is editable $col["hidden"] = false; $col["viewable"] = true; $col["search"] = true; $col["sortable"] = true; $cols[] = $col; $g = new jqgrid(); $grid["caption"] = "Videos"; // $grid["multiselect"] = true; $grid["autowidth"] = true; $grid["resizable"] = true; //$grid["toppager"] = true; $grid["sortname"] = 'Video_ID'; $grid["sortorder"] = "ASC"; $grid["add_options"] = array( 'width'=>'420', "closeAfterEdit"=>true, // close dialog after add/edit "top"=>"200", // absolute top position of dialog "left"=>"200" // absolute left position of dialog ); $g->set_options($grid); $g->set_actions(array( "add"=>true, // allow/disallow add "edit"=>true, // allow/disallow edit "delete"=>true, // allow/disallow delete "rowactions"=>true, // show/hide row wise edit/del/save option "export"=>true, // show/hide export to excel option "autofilter" => true, // show/hide autofilter for search "search" => "advance" // show single/multi field search condition (e.g. simple or advance) ) ); $g->select_command = "SELECT Videos.* FROM Videos"; // set database table for CRUD operations $g->table = "Videos"; $g->set_columns($cols); // group columns header $g->set_group_header( array( "useColSpanStyle"=>true, "groupHeaders"=>array( array( "startColumnName"=>'Video_ID', // group starts from this column "numberOfColumns"=>4, // group span to next 2 columns "titleText"=>'Videos' // caption of group header ), ) ) ); // render grid and get html/js output $out = $g->render("Videos"); $this->render('index',array( 'out'=>$out, )); }