public function postAdd()
 {
     $fields = ["name" => Input::get("name")];
     $rules = ["name" => "required|max:255"];
     $customMessages = ["name.required" => "Поле \"Наименование должности\" обязательно для заполнения"];
     $validator = Validator::make($fields, $rules, $customMessages);
     if ($validator->fails()) {
         $error = "";
         foreach (array_keys($fields) as $k) {
             $message = $validator->messages()->first($k);
             if ($message) {
                 $error .= "<div>" . $message . "</div>";
             }
         }
         return Redirect::to($_SERVER["HTTP_REFERER"])->with("error", $error);
     }
     $item = new Position();
     $item->department_id = Input::get("department", NULL) ? Input::get("department") : NULL;
     $item->chief_position_id = Input::get("chief", NULL) ? Input::get("chief") : NULL;
     $item->position_role_id = Input::get("role", NULL) ? Input::get("role") : NULL;
     $item->name = Input::get("name");
     $item->name_rp = Input::get("name_rp");
     $item->comment = Input::get("comment");
     $item->workshift_id = Input::get("workshift_id", NULL) ? Input::get("workshift_id") : NULL;
     $item->type_regime = in_array((string) Input::get("type_regime"), ["shifts", "schedule", "irregular"]) ? (string) Input::get("type_regime") : NULL;
     $item->from_hour = Input::get("from_hour", NULL) ? Input::get("from_hour") : NULL;
     $item->from_min = Input::get("from_min", NULL) ? Input::get("from_min") : NULL;
     $item->to_hour = Input::get("to_hour", NULL) ? Input::get("to_hour") : NULL;
     $item->to_min = Input::get("to_min", NULL) ? Input::get("to_min") : NULL;
     $item->save();
     return Redirect::to("/structure/positions")->with("message", "Позиция успешно опубликована");
 }
 /**
  * Создает новую модель Положения.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new Position();
     if (Yii::app()->getRequest()->getPost('Position') !== null) {
         $model->setAttributes(Yii::app()->getRequest()->getPost('Position'));
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('ListnerModule.listner', 'Запись добавлена!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id]));
         }
     }
     $this->render('create', ['model' => $model]);
 }
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Position();
     if (isset($_POST['Position'])) {
         $model->attributes = $_POST['Position'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionCreate()
 {
     $model = new Position();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Position'])) {
         $model->attributes = $_POST['Position'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->position_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  * POST /position
  *
  * @return Response
  */
 public function store()
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $validation = Validator::make($input, Position::$rules);
     if ($validation->passes()) {
         $position = new Position();
         $position->position = strtoupper(Input::get('position'));
         $position->save();
         return Redirect::route('designated-position.index')->with('class', 'success')->with('message', 'Record successfully created.');
     } else {
         return Redirect::route('designated-position.create')->withInput()->withErrors($validation)->with('class', 'error')->with('message', 'There were validation error.');
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Position::$rules);
     var_dump(Input::all());
     // process the login
     if ($validator->fails()) {
         return Redirect::to('positions/create')->withErrors($validator)->withInput(Input::except('password'));
     } else {
         $position = new Position();
         $position->name = Input::get('name');
         $position->save();
         Logfile::addData('thêm', 'Ngiệp sư', $position->id, $position->name);
         // redirect
         Session::flash('message', 'Thêm tin mới thành công!');
         return Redirect::to('positions');
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Position();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Position'])) {
         $model->attributes = $_POST['Position'];
         if ($model->save()) {
             date_default_timezone_set("Asia/Manila");
         }
         $activity = new Activity();
         $activity->act_desc = 'Added Another Position';
         $activity->act_datetime = date('Y-m-d G:i:s');
         $activity->act_by = User::model()->findByPK(Yii::app()->user->name)->emp_id;
         $activity->save();
         $this->redirect(array('view', 'id' => $model->pos_id));
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * @covers ::getByArea
  */
 public function testGetByArea()
 {
     $position = (object) array('positionId' => 1, 'positionName' => 'MY POSITION', 'positionDescription' => 'THIS IS A COOL JOB', 'employeeArea' => 2, 'deleted' => 0, 'guid' => null);
     $position2 = (object) array('positionId' => 2, 'positionName' => 'MY POSITION', 'positionDescription' => 'THIS IS A COOL JOB', 'employeeArea' => 2, 'deleted' => 0, 'guid' => null);
     $accessor = new Position();
     $model = new Position();
     $model->save($position);
     $model2 = new Position();
     $model2->save($position2);
     $position = $accessor->getByArea(2);
     $this->assertEquals(2, count($position));
     // Clean up
     $host = getenv('DBHOST');
     $user = getenv('DBUSER');
     $pass = getenv('DBPASS');
     $db = getenv('DBNAME');
     $connectStr = "mysql:dbname=" . $db . ";host=" . $host . ";port=3306";
     $options = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ);
     $pdo = new \PDO($connectStr, $user, $pass, $options);
     $stmt = $pdo->prepare("DELETE FROM positions");
     $stmt->execute();
 }
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $web = new sfWebBrowser();
     $latest = Doctrine::getTable('Position')->createQuery('p')->limit(1)->orderBy('p.timestamp DESC')->fetchOne();
     $this->logSection($this->namespace, 'Getting latest instamapper positions');
     $instamapper = $web->get('http://www.instamapper.com/api?action=getPositions&key=' . sfConfig::get('app_instamapper_api_key') . '&num=1000' . ($latest instanceof Position ? '&from_ts=' . $latest->getTimestamp() : '') . '&format=json');
     try {
         if (!$instamapper->responseIsError()) {
             $json = json_decode($instamapper->getResponseText());
             foreach ($json->positions as $gps) {
                 if (!$latest instanceof Position || $gps->timestamp >= $latest->getTimestamp()) {
                     $position = new Position();
                     $position->setDeviceKey($gps->device_key);
                     $position->setDeviceLabel($gps->device_label);
                     $position->setTimestamp($gps->timestamp);
                     $position->setLatitude($gps->latitude);
                     $position->setLongitude($gps->longitude);
                     $position->setAltitude($gps->altitude);
                     $position->setSpeed($gps->speed);
                     $position->setHeading($gps->heading);
                     $position->save();
                     echo '.';
                     $this->new++;
                 }
             }
         } else {
             // Error response (eg. 404, 500, etc)
         }
     } catch (Exception $e) {
         // Adapter error (eg. Host not found)
     }
     echo "\n";
     $this->logSection($this->namespace, 'Done: ' . $this->new . ' added.');
 }
 public function actionCreateNextGroup($id, $parent_group)
 {
     $roles = ['1', '3'];
     $role = \Yii::app()->user->role;
     if (array_intersect($role, $roles)) {
         $model = new Position();
         $listner = Listner::model()->findByPk($id)->branch_id;
         if (Yii::app()->getRequest()->getPost('Position') !== null) {
             $model->setAttributes(Yii::app()->getRequest()->getPost('Position'));
             $model->parent_group = $parent_group;
             if (in_array('3', $role) && !in_array('1', $role)) {
                 $model->branch_id = Yii::app()->user->branch->id;
             }
             if (isset($_POST['group'])) {
                 $model->group = $_POST['group'];
             } else {
                 $model->group = NULL;
             }
             if (isset($_POST['hui'])) {
                 $model->hui = $_POST['hui'];
             } else {
                 $model->hui = NULL;
             }
             $model->listner_id = $id;
             if (!$model->save()) {
                 die(var_dump($model->getErrors()));
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('ListnerModule.listner', 'Запись добавлена!'));
                 $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id]));
             }
         }
         $this->render('create', ['model' => $model, 'listner' => $listner]);
     } else {
         throw new CHttpException(403, 'Ошибка прав доступа.');
     }
 }
 public function actionUpload()
 {
     parent::actionUpload();
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $file = $folder . basename($_FILES['uploadfile']['name']);
     if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
         $row = 0;
         if (($handle = fopen($file, "r")) !== FALSE) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 if ($row > 0) {
                     $model = Position::model()->findByPk((int) $data[0]);
                     if ($model === null) {
                         $model = new Position();
                     }
                     $model->positionid = (int) $data[0];
                     $model->positionname = $data[1];
                     $model->recordstatus = (int) $data[2];
                     try {
                         if (!$model->save()) {
                             $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
                         }
                     } catch (Exception $e) {
                         $this->messages = $this->messages . $e->getMessage();
                     }
                 }
                 $row++;
             }
         } else {
             $this->messages = $this->messages . ' memory or harddisk full';
         }
         fclose($handle);
     } else {
         $this->messages = $this->messages . ' check your directory permission';
     }
     if ($this->messages == '') {
         $this->messages = 'success';
     }
     echo $this->messages;
 }