Example #1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aDepartment !== null) {
             if ($this->aDepartment->isModified() || $this->aDepartment->isNew()) {
                 $affectedRows += $this->aDepartment->save($con);
             }
             $this->setDepartment($this->aDepartment);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = InstructorPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = InstructorPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += InstructorPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collCourseInstructorAssociations !== null) {
             foreach ($this->collCourseInstructorAssociations as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collInstructorDetails !== null) {
             foreach ($this->collInstructorDetails as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->department_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', '创建成功');
             $this->redirect(array('update', 'id' => $model->d_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created branch in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Department::$rules, Department::$messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $department = new Department();
     $department->department_name = Input::get('name');
     $department->organization_id = '1';
     $department->save();
     return Redirect::route('departments.index');
 }
Example #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if ($model->save()) {
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #6
0
 public function executeAdd(sfWebRequest $request)
 {
     if ($request->isMethod('Post')) {
         $department = new Department();
         $department->setTitle($request->getParameter('title'));
         //$department->setDescription($request->getParameter('description'));
         $department->setStatus(Constant::RECORD_STATUS_ACTIVE);
         $department->save();
         $this->getUser()->setFlash('SUCCESS_MESSAGE', Constant::RECORD_ADDED_SUCCESSFULLY);
         $this->redirect('Department/list');
     }
     //end if
 }
 /**
  * Store a newly created resource in storage.
  * POST /department
  *
  * @return Response
  */
 public function store()
 {
     Input::merge(array_map('trim', Input::all()));
     $input = Input::all();
     $validation = Validator::make($input, Department::$rules);
     if ($validation->passes()) {
         $department = new Department();
         $department->department = strtoupper(Input::get('department'));
         $department->save();
         return Redirect::route('department.index')->with('class', 'success')->with('message', 'Record successfully created.');
     } else {
         return Redirect::route('department.create')->withInput()->withErrors($validation)->with('class', 'error')->with('message', 'There were validation error.');
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if ($model->save()) {
             $this->audit->logAudit(Yii::app()->user->id, new DateTime(), Constants::AUDITORIA_OBJETO_DEPARTAMENTO, Constants::AUDITORIA_OPERACION_ALTA, $model->id);
             $this->render('/site/successfullOperation', array('header' => 'Departamento creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de departamentos', 'returnUrl' => Yii::app()->createUrl('department/admin'), 'viewUrl' => Yii::app()->createUrl("department/view", array("id" => $model->id))));
             return;
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionCreate()
 {
     $model = new Department();
     $model->company_id = $this->companyId;
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = Yii::app()->request->getPost('Department');
         $model->create_at = date('Y-m-d H:i:s', time());
         $model->update_at = date('Y-m-d H:i:s', time());
         if ($model->save()) {
             Yii::app()->user->setFlash('success', yii::t('app', '添加成功'));
             $this->redirect(array('department/index', 'companyId' => $this->companyId));
         }
     }
     $printers = $this->getPrinterList();
     $this->render('create', array('model' => $model, 'printers' => $printers));
 }
 function testFind()
 {
     //Arrange
     $name = "Math";
     $id = 1;
     $test_department = new Department($name, $id);
     $test_department->save();
     $name2 = "Business";
     $id2 = 2;
     $test_department2 = new Department($name2, $id2);
     $test_department2->save();
     //Act
     $id = $test_department->getId();
     $result = Department::find($id);
     //Assert
     $this->assertEquals($test_department, $result);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if (User::getMyCompany() == $model->company_id || Yii::app()->user->role == 1) {
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         } else {
             throw new CHttpException(403, 'У вас закрыт доступ к редактированию этой организации');
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function store()
 {
     Auth::isAdminOrDie(App::$instance);
     Token::checkToken();
     $request = $this->request->request;
     $this->validator->validate(['Префикс' => [$request->get('prefix'), 'required|int'], 'Название' => [$request->get('name'), 'required|max(255)']]);
     //if no passes
     if (!$this->validator->passes()) {
         App::$instance->MQ->setMessage($this->validator->errors()->all());
         ST::redirect("back");
     }
     $dep = new Department();
     $dep->fill($request->all());
     $dep->save();
     App::$instance->MQ->setMessage("Успешно создано");
     App::$instance->log->logWrite(LOG_CONFIG_CHANGE, 'Добавлено подразделение' . $dep->name);
     ST::redirectToRoute('Departments/index');
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         $model->branch = Yii::app()->session->get('branch_id');
         $model->created_by = Yii::app()->session->get('user_id');
         $model->created_on = date('Y-m-d H:i:s');
         $model->modified_by = Yii::app()->session->get('user_id');
         $model->modified_on = date('Y-m-d H:i:s');
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #14
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         $model->attributes = $_POST['Department'];
         if ($model->save()) {
             date_default_timezone_set("Asia/Manila");
         }
         $activity = new Activity();
         $activity->act_desc = 'Added Another Department';
         $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->dept_id));
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  * POST /department
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Department::$rules);
     $row = Department::where('id_dept', '=', Input::get('id_dept'));
     if ($validator->fails()) {
         return Redirect::to('department')->withErrors($validator)->withInput(Input::all());
     } else {
         if (Department::where('id_dept', '=', Input::get('id_dept'))->exists()) {
             $department = Department::find(Input::get('id_dept'));
             $department->nm_dept = Input::get('nm_dept');
             $department->save();
             Session::flash('message', 'Successfully updated Department!');
             return Redirect::to('department');
         } else {
             $department = new Department();
             $department->id_dept = Input::get('id_dept');
             $department->nm_dept = Input::get('nm_dept');
             $department->save();
             Session::flash('message', 'Successfully created Department!');
             return Redirect::to('department');
         }
     }
     //
 }
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->forward("companies/index");
     }
     $companies = new Department();
     $companies->name = $this->request->getPost("name", "striptags");
     if ($companies->name == '') {
         $this->flash->error("名称不能为空");
         return $this->forward("companies/new");
     } else {
         $companies->telephone = $this->request->getPost("telephone", "striptags");
         $companies->city = $this->request->getPost("city", "striptags");
         $companies->address = $this->request->getPost("address", "striptags");
         $companies->contacts = $this->request->getPost("contacts", "striptags");
         if (!$companies->save()) {
             foreach ($companies->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
             return $this->forward("companies/new");
         }
         /* 
         			$this->flash->success("部门信息保存成功");
         			return $this->forward("companies/search"); */
         $this->response->redirect("companies/search");
     }
 }
 /**
  * Add a department to database with the passed name.
  */
 public static function add($name)
 {
     $name = trim($name);
     if ($name == '') {
         return NQ::simple('intern', INTERN_WARNING, 'No name given for new major. No major was added.');
     }
     $db = self::getDb();
     $db->addWhere('name', $name);
     if ($db->select('count') > 0) {
         NQ::simple('intern', INTERN_WARNING, "Department <i>{$name}</i> already exists.");
         return;
     }
     // Create the new Department Obj.
     $dept = new Department();
     $dept->name = $name;
     $dept->hidden = 0;
     // Be sure to set a default value for this, otherwise it gets set to null and screws things up
     $dept->corequisite = 0;
     // Be sure to set a default value for this, otherwise it gets set to null and screws things up
     $dept->save();
     // Successfully saved department to DB. Alert user and remind them the department they just saved.
     NQ::simple('intern', INTERN_SUCCESS, "Department <i>{$name}</i> added.");
 }
Example #18
0
 private function updatesimple($typic, $grtype, $result, &$info)
 {
     if ($typic == 2) {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid " . " FROM tmp_xml a WHERE a.user="******" AND a.ctype=" . $typic;
     } else {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid," . " b.id AS g_id, b.ckey AS  g_key, b.cname AS g_name, b.lid as g_lid " . " FROM tmp_xml a LEFT JOIN  tmp_xml b ON a.cgr=b.ckey AND b.user="******" AND b.ctype=" . $grtype . " WHERE a.user="******" AND a.ctype=" . $typic;
     }
     $recs = Yii::app()->db->createCommand($sql)->query();
     //we got the records for tmp_xml table
     $i = 0;
     $j = 0;
     $jj = 0;
     if (count($recs) > 0) {
         foreach ($recs as $value) {
             $doprod = 0;
             $doprodid = 0;
             $edid = 0;
             if ($value['p_lid'] === null) {
                 if ($result[$value['p_id']] === null) {
                     $doprod = -1;
                     $doprodid = 1;
                 } else {
                     $edid = (int) $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 2;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 1;
                     }
                 }
             } else {
                 if ($result[$value['p_id']] === null) {
                     $doprod = $value['p_lid'];
                 } else {
                     $edid = $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 3;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 4;
                     }
                 }
             }
             $grid = 0;
             if ($doprod < 0) {
                 if ($typic != 2) {
                     if ($value['g_lid'] === null) {
                         if ($typic == 0) {
                             $prodid = ProductgroupId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         } else {
                             $prodid = CountryId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         }
                         if ($prodid === null) {
                             if ($typic == 0) {
                                 $group = new ProductGroup();
                                 $group->tnam = $value['g_name'];
                                 $group->save();
                                 $grid = $group->ckey;
                                 $groupid = new ProductgroupId();
                             } else {
                                 $group = new Country();
                                 $group->name = $value['g_name'];
                                 $group->save();
                                 $grid = $group->id;
                                 $groupid = new CountryId();
                             }
                             $groupid->ckey = $value['g_key'];
                             $groupid->db = 1;
                             $groupid->id = $grid;
                             $groupid->save();
                             $i++;
                         } else {
                             $grid = $prodid->id;
                         }
                     } else {
                         $grid = $value['g_lid'];
                     }
                 } else {
                     $grid = 1;
                 }
                 if ($grid > 0) {
                     if ($typic == 0) {
                         $prod = new Product();
                         $prod->tnam = $value['p_name'];
                         $prod->cgr = $grid;
                         $it = TmpXml::model()->find('ctype=:ctype AND ckey=:ckey AND user=:user', array(':ctype' => 10, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid));
                         if ($it) {
                             $prod->it = (int) $it->cname;
                         }
                         $prod->save();
                         $grid = $prod->ckey;
                     } else {
                         if ($typic == 1) {
                             $prod = new Client();
                             $prod->name = $value['p_name'];
                             $prod->country_id = $grid;
                             $prod->save();
                             $grid = $prod->id;
                             $this->updateprop($value['p_key'], $grid);
                             $this->updatebank($value['p_key'], $grid);
                         } else {
                             $prod = new Department();
                             $prod->name = $value['p_name'];
                             $prod->save();
                             $grid = $prod->id;
                             $this->updatebank($value['p_key'], $grid, 0);
                         }
                     }
                     $j++;
                     if ($doprodid == 1) {
                         if ($typic == 0) {
                             $prodid = new ProductId();
                         } else {
                             if ($typic == 1) {
                                 $prodid = new ClientId();
                             } else {
                                 $prodid = new DepartmentId();
                             }
                         }
                         $prodid->ckey = $value['p_key'];
                         $prodid->db = 1;
                         $prodid->id = $grid;
                         $prodid->save();
                     } else {
                         if ($typic == 0) {
                             $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             if ($typic == 1) {
                                 $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             } else {
                                 $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             }
                         }
                         if (!($prodid === null)) {
                             $prodid->id = $grid;
                             $prodid->save();
                         }
                     }
                 }
             }
             if ($doprodid == 2) {
                 if ($typic == 0) {
                     $prodid = new ProductId();
                 } else {
                     if ($typic == 1) {
                         $prodid = new ClientId();
                     } else {
                         $prodid = new DepartmentId();
                     }
                 }
                 $prodid->ckey = $value['p_key'];
                 $prodid->db = 1;
                 $prodid->id = $edid;
                 $prodid->save();
             } else {
                 if ($doprodid == 3) {
                     if ($typic == 0) {
                         $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                     } else {
                         if ($typic == 1) {
                             $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         }
                     }
                     if (!($prodid === null)) {
                         $prodid->id = $edid;
                         $prodid->save();
                     }
                 }
             }
             if ($doprod > 0) {
                 if ($typic == 0) {
                     $prod = Product::model()->findByPk($doprod);
                     if (!($prod === null)) {
                         if ($prod->tnam != $value['p_name']) {
                             $prod->tnam = $value['p_name'];
                             $prod->save();
                             $jj = 0;
                         }
                     }
                 } else {
                     if ($typic == 1) {
                         $prod = Client::model()->findByPk($doprod);
                         if (!($prod === null)) {
                             if ($prod->name != $value['p_name']) {
                                 $prod->name = $value['p_name'];
                                 $prod->save();
                                 $jj = 0;
                             }
                             $this->updateprop($value['p_key'], $prod->id);
                             $this->updatebank($value['p_key'], $prod->id);
                         }
                     } else {
                         if (!($prop = DepartmentProp::model()->findByPk(array('id' => $doprod, '_key' => 'stop')))) {
                             $prod = Department::model()->findByPk($doprod);
                             if (!($prod === null)) {
                                 if ($prod->name != $value['p_name']) {
                                     $prod->name = $value['p_name'];
                                     $prod->save();
                                     $jj = 0;
                                 }
                             }
                             $this->updatebank($value['p_key'], $doprod, 0);
                         }
                     }
                 }
             }
         }
     }
     if ($typic == 0) {
         $info[] = 'Создано новых групп товаров:' . $i;
         $info[] = 'Создано новых товаров:' . $j;
         $info[] = 'Обновлено товаров:' . $jj;
     } else {
         if ($typic == 1) {
             $info[] = 'Создано новых групп клиентов:' . $i;
             $info[] = 'Создано новых клиентов:' . $j;
             $info[] = 'Обновлено клиентов:' . $jj;
         } else {
             $info[] = 'Создано новых фирм:' . $j;
             $info[] = 'Обновлено фирм:' . $jj;
         }
     }
     return;
 }
Example #19
0
 public function actionEditMolUser($table, $action, $id, $value)
 {
     switch ($table) {
         case 'po_name':
             switch ($action) {
                 case 'add':
                     $po_name = new po_name();
                     $po_name->po_name = $value;
                     $po_name->po_type_id = $id;
                     if ($po_name->save()) {
                         $result = 'ПО добавлено';
                     }
                     break;
                 case 'delete':
                     $po_name = po_name::findOne($id);
                     if ($po_name->active == '1') {
                         $po_name->active = '0';
                     } else {
                         $po_name->active = '1';
                     }
                     if ($po_name->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $po_name = po_name::findOne($id);
                         $po_name->po_name = $value;
                         if ($po_name->save()) {
                             $result = 'ПО переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'po_type':
             switch ($action) {
                 case 'add':
                     $po_type = new po_type();
                     $po_type->po_type = $value;
                     if ($po_type->save()) {
                         $result = 'Тип ПО добавлен';
                     }
                     break;
                 case 'delete':
                     $po_type = po_type::findOne($id);
                     if ($po_type->active == '1') {
                         $po_type->active = '0';
                     } else {
                         $po_type->active = '1';
                     }
                     if ($po_type->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $po_type = po_type::findOne($id);
                         $po_type->po_type = $value;
                         if ($po_type->save()) {
                             $result = 'Тип ПО переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'mol':
             switch ($action) {
                 case 'add':
                     $mol = new mol();
                     $mol->value = $value;
                     if ($mol->save()) {
                         $result = 'МОЛ добавлено';
                     }
                     break;
                 case 'delete':
                     $mol = mol::findOne($id);
                     if ($mol->active == '1') {
                         $mol->active = '0';
                     } else {
                         $mol->active = '1';
                     }
                     if ($mol->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $mol = mol::findOne($id);
                         $mol->value = $value;
                         if ($mol->save()) {
                             $result = 'МОЛ переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'cpu':
             switch ($action) {
                 case 'add':
                     $cpu = new cpu();
                     $cpu->name = $value;
                     if ($cpu->save()) {
                         $result = 'Процессор добавлен';
                     }
                     break;
                 case 'delete':
                     $cpu = cpu::findOne($id);
                     if ($cpu->active == '1') {
                         $cpu->active = '0';
                     } else {
                         $cpu->active = '1';
                     }
                     if ($cpu->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $cpu = cpu::findOne($id);
                         $cpu->name = $value;
                         if ($cpu->save()) {
                             $result = 'Процессор переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'cartridge_type':
             switch ($action) {
                 case 'add':
                     $type = new CartridgeType();
                     $type->type = $value;
                     if ($type->save()) {
                         $result = 'Тип картриджа добавлен';
                     }
                     break;
                 case 'delete':
                     $type = CartridgeType::find()->where(['type' => $id])->One();
                     if ($type->delete()) {
                         $result = 'Тип картриджа удален';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $type = CartridgeType::find()->where(['type' => $id])->One();
                         $type->type = $value;
                         if ($type->update()) {
                             $result = 'Картридж переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'consignment':
             switch ($action) {
                 case 'add':
                     $consignment = new consignment();
                     $consignment->name = $value;
                     if ($consignment->save()) {
                         $result = 'Партия добавлена';
                     } else {
                         $result = 'Партия НЕ добавлена';
                     }
                     break;
                 case 'delete':
                     // $query_str = 'UPDATE consignment SET active = NOT active WHERE id = "'.$id.'"';
                     //$consignment = consignment::findOne($id);
                     //if ($consignment -> active == '1') $consignment -> active = '0'; else $consignment -> active = '1';
                     //$consignment -> save();
                     //$result = 'Статус изменен';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $consignment = consignment::findOne($id);
                         $consignment->name = $value;
                         if ($consignment->save()) {
                             $result = 'Партия переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'type':
             switch ($action) {
                 case 'add':
                     $device_type = new deviceType();
                     $device_type->value = $value;
                     if ($device_type->save()) {
                         $result = 'Тип добавлен';
                     }
                     break;
                 case 'delete':
                     $device_type = deviceType::findOne($id);
                     if ($device_type->active == '1') {
                         $device_type->active = '0';
                     } else {
                         $device_type->active = '1';
                     }
                     if ($device_type->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $device_type = deviceType::findOne($id);
                         $device_type->value = $value;
                         if ($device_type->save()) {
                             $result = 'Тип переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'mark':
             switch ($action) {
                 case 'add':
                     $mark = new trademarks();
                     $mark->value = $value;
                     if ($mark->save()) {
                         $result = 'Марка добавлена';
                     }
                     break;
                 case 'delete':
                     $mark = mark::findOne($id);
                     if ($mark->active == '1') {
                         $mark->active = '0';
                     } else {
                         $mark->active = '1';
                     }
                     if ($mark->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     if ($value != '') {
                         $mark = mark::findOne($id);
                         $mark->value = $value;
                         if ($mark->save()) {
                             $result = 'Марка переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'user':
             switch ($action) {
                 case 'add':
                     $user = new user();
                     $user->name = $value;
                     $user->password = sha1('1');
                     if ($user->save()) {
                         $result = 'Сотрудник добавлен';
                     }
                     break;
                 case 'delete':
                     if ($value != '') {
                         $user = user::findOne($id);
                         if ($user->active == '1') {
                             $user->active = '0';
                         } else {
                             $user->active = '1';
                         }
                         if ($user->save()) {
                             $result = 'Статус изменен';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'edit':
                     $user = user::findOne($id);
                     $user->name = $value;
                     if ($user->save()) {
                         $result = 'Сотрудник переименован';
                     }
                     break;
             }
             break;
         case 'room':
             switch ($action) {
                 case 'add':
                     $room = new room();
                     $room->value = $value;
                     $room->building_id = $id;
                     if ($room->save()) {
                         $result = 'Кабинет добавлен';
                     } else {
                         $result = print_r($room->getErrors());
                     }
                     break;
                 case 'delete':
                     $room = room::findOne($id);
                     if ($room->active == '1') {
                         $room->active = '0';
                     } else {
                         $room->active = '1';
                     }
                     $room->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $room = room::findOne($id);
                         $room->value = $value;
                         if ($room->save()) {
                             $result = 'Кабинет переименован';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'device':
             switch ($action) {
                 case 'add':
                     switch (substr($id, 0, 3)) {
                         case 'mrk':
                             $result = 'Марка не добавлена! Выберите тип устройства для добавления!';
                             break;
                         case 'typ':
                             $type_id = intval(substr($id, 4));
                             $trademark = new trademark();
                             $trademark->value = $value;
                             $TypeLinkMark = new TypeLinkMark();
                             $TypeLinkMark->type_id = $type_id;
                             $TypeLinkMark->mark_id = Yii::app()->db->getLastInsertID();
                             if ($TypeLinkMark->save() && $trademark->save()) {
                                 $result = 'Марка добавлена';
                             }
                             break;
                     }
                     break;
                 case 'delete':
                     $device = new device();
                     $device->value = $value;
                     if ($device->save()) {
                         $result = 'Статус изменен';
                     }
                     break;
                 case 'edit':
                     $query_str = 'UPDATE user SET value = "' . $value . '" WHERE id = "' . $id . '"';
                     $result = 'Сотрудник переименован';
                     break;
             }
             break;
         case 'model':
             switch ($action) {
                 case 'add':
                     $model = new model();
                     $model->value = $value;
                     $model->save();
                     $result = 'Модель добавлена';
                     break;
                 case 'delete':
                     $model = model::findOne($id);
                     if ($model->active == '1') {
                         $model->active = '0';
                     } else {
                         $model->active = '1';
                     }
                     $model->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $model = model::findOne($id);
                         $model->value = $value;
                         if ($model->save()) {
                             $result = 'Модель переименована';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
             }
             break;
         case 'department':
             switch ($action) {
                 case 'delete':
                     //$result = 'Статус изменен';
                     $department = department::findOne($id);
                     if ($department->active == '1') {
                         $department->active = '0';
                     } else {
                         $department->active = '1';
                     }
                     $department->save();
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $department = department::findOne($id);
                         $department->value = $value;
                         if ($department->save()) {
                             $result = 'Подразделение переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'add':
                     $department = new Department();
                     $department->value = $value;
                     if ($department->save()) {
                         $result = 'Подразделение добавлено';
                     }
                     break;
             }
             break;
         case 'building':
             switch ($action) {
                 case 'delete':
                     $building = building::findOne($id);
                     if ($building->active == '1') {
                         $building->active = '0';
                     } else {
                         $building->active = '1';
                     }
                     $building->save();
                     //$result = 'Статус изменен';
                     $result = '';
                     break;
                 case 'edit':
                     if ($value != '') {
                         $building = building::findOne($id);
                         $building->value = $value;
                         if ($building->save()) {
                             $result = 'Здание переименовано';
                         }
                     } else {
                         $result = 'Введите новое наименование!';
                     }
                     break;
                 case 'add':
                     $building = new Building();
                     $building->value = $value;
                     $building->department_id = $id;
                     if ($building->save()) {
                         $result = 'Здание добавлено';
                     }
                     break;
             }
             break;
     }
     echo $result;
 }
Example #20
0
 public function excelAction($path)
 {
     //phalcon向数据库导入的时候有点小问题,有default值的列需要赋值,不然这列的default值不会写入数据库
     include '../app/classes/PHPExcel.php';
     $this->view->disable();
     $obj = new PHPExcel();
     $name = '/home/sify/' . $path;
     $type = PHPExcel_IOFactory::identify($name);
     $reader = PHPExcel_IOFactory::createReader($type);
     $obj = $reader->load($name);
     //导入hospital子表
     $sheet = $obj->getSheetByName('hospital');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $hospital = new Hospital();
         $hospital->id = $sheet->getCell('A' . $j)->getValue();
         $hospital->name = (string) $sheet->getCell('B' . $j)->getValue();
         $hospital->intro = (string) $sheet->getCell('C' . $j)->getValue();
         $hospital->cityid = $sheet->getCell('D' . $j)->getValue();
         $hospital->street = (string) $sheet->getCell('E' . $j)->getValue();
         $hospital->tele = (string) $sheet->getCell('F' . $j)->getValue();
         $hospital->level = (string) $sheet->getCell('G' . $j)->getValue();
         $hospital->notice = (string) $sheet->getCell('H' . $j)->getValue();
         $hospital->img = '/img/hospital/default.img';
         $hospital->save();
     }
     //导入department子表
     $sheet = $obj->getSheetByName('department');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $department = new Department();
         $department->id = $sheet->getCell('A' . $j)->getValue();
         $department->h_id = $sheet->getCell('B' . $j)->getValue();
         $department->type = (string) $sheet->getCell('C' . $j)->getValue();
         $department->intro = (string) $sheet->getCell('D' . $j)->getValue();
         $department->name = (string) $sheet->getCell('E' . $j)->getValue();
         $department->dcount = 0;
         $department->save();
     }
     //导入doctor子表
     $sheet = $obj->getSheetByName('doctor');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $doctor = new Doctor();
         $doctor->id = $sheet->getCell('A' . $j)->getValue();
         $doctor->name = (string) $sheet->getCell('B' . $j)->getValue();
         $doctor->de_id = $sheet->getCell('C' . $j)->getValue();
         $doctor->post = (string) $sheet->getCell('D' . $j)->getValue();
         $doctor->intro = (string) $sheet->getCell('E' . $j)->getValue();
         $doctor->specialty = (string) $sheet->getCell('F' . $j)->getValue();
         $doctor->fee = $sheet->getCell('G' . $j)->getValue();
         $doctor->img = '/img/doctor/default.img';
         $doctor->save();
     }
     //导入available子表
     $sheet = $obj->getSheetByName('available');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $available = new Available();
         $available->id = $sheet->getCell('A' . $j)->getValue();
         $available->do_id = $sheet->getCell('B' . $j)->getValue();
         $available->date = $sheet->getCell('C' . $j)->getFormattedValue();
         $available->time = $sheet->getCell('D' . $j)->getValue();
         $available->save();
     }
     echo '数据导入成功!';
 }
 /**
  * Create new employee department choice
  *
  * @return mixed
  */
 public function createDept()
 {
     $rules = ['name' => 'required|alpha_spaces'];
     $v = Validator::make(Input::all(), $rules);
     if ($v->fails()) {
         return Redirect::back()->withErrors($v);
     } else {
         $dept = new Department();
         $name = Input::get('name');
         $dept->name = $name;
         $dept->save();
         return Redirect::route('manageDepartments')->with('flash_message', 'Department created');
     }
 }
Example #22
0
 function save()
 {
     $this->filter_access('Departement', 'roled_add', 'departments/index');
     $dept = new Department();
     $dept->dept_name = $this->input->post('dept_name');
     if ($dept->save()) {
         $this->session->set_flashdata('message', 'Departments successfully created!');
         redirect('departments/');
     } else {
         // Failed
         $dept->error_message('custom', 'Department Name required');
         $msg = $dept->error->custom;
         $this->session->set_flashdata('message', $msg);
         redirect('departments/add');
     }
 }
 /**
  * Start browsing the directory and register files
  *
  * @return       Exception code = 400 if directory non-existent
  *               An array containing list of non-imported files if successful
  */
 public function doImport()
 {
     if (!file_exists($this->_dir)) {
         throw new Exception("directory non-existent", 400);
     }
     $errArr = array();
     $handler = opendir($this->_dir);
     // TODO: does not do recrusive listing, do we need that?
     while (false !== ($file = readdir($handler))) {
         if ($file != '.' && $file != '..') {
             $err = false;
             $pos = strrpos($file, '.');
             $fileName = strtoupper(substr($file, 0, $pos));
             $token = strtok($fileName, '_');
             $counter = 0;
             while (false !== $token) {
                 switch ($counter) {
                     case 0:
                         if (strlen($token) != 7) {
                             $err = true;
                         }
                         $rawCourseCode = $token;
                         break;
                     case 1:
                         if ($token != substr($this->_year, 0, 4)) {
                             $err = true;
                         }
                         break;
                     case 2:
                         if ($token != "EXAM") {
                             if (substr($token, 0, 5) == "EXAM(") {
                                 // name could have the following syntax: AER205S_2009_EXAM(2).pdf
                                 $count = strtok($token, '(');
                                 $count = strtok('(');
                                 $count = strtok($count, ')');
                                 if ($count === false || !is_numeric($count)) {
                                     $err = true;
                                 }
                             } else {
                                 $err = true;
                             }
                         }
                         break;
                 }
                 $token = strtok("_");
                 $counter++;
             }
             if ($counter != 3 || $err) {
                 $err = true;
             } else {
                 // assume course code is 7 chars in length with the last char being either S, F or Y
                 $part1 = substr($rawCourseCode, 0, 6);
                 //e.g. AER205
                 $part2 = substr($rawCourseCode, 6, 1);
                 //e.g. F
                 switch ($part2) {
                     case "F":
                     case "S":
                         $courseCode = $part1 . "H1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     case "Y":
                         $courseCode = $part1 . "Y1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     default:
                         $err = true;
                         break;
                 }
                 if (!$err) {
                     $conn = Propel::getConnection();
                     // check if we have exam of this descr already
                     $examArr = ExamPeer::getExamsForYearAndCourseId($courseCode, $this->_year, $conn);
                     foreach ($examArr as $ex) {
                         if ($ex->getType() == EnumItemPeer::EXAM && $ex->getDescr() == $descr) {
                             $err = true;
                             break;
                         }
                     }
                     if (!$err) {
                         // first check if course exists
                         $course = CoursePeer::retrieveByPK($courseCode, $conn);
                         if (!isset($course)) {
                             $course = new Course();
                             //$course->setDeptId(substr($courseCode, 0, 3));
                             $course->setDescr($courseCode);
                             $course->setIsEng(1);
                             $course->setId($courseCode);
                             $dept = DepartmentPeer::retrieveByPK(substr($courseCode, 0, 3), $conn);
                             if (!isset($dept)) {
                                 $dept = new Department();
                                 $dept->setId(substr($courseCode, 0, 3));
                                 $dept->setDescr(substr($courseCode, 0, 3));
                                 $dept->save($conn);
                             }
                             $course->setDepartment($dept);
                             $course->save($conn);
                         }
                         // register exam
                         $exam = new Exam();
                         $exam->setType(EnumItemPeer::EXAM);
                         $exam->setDescr($descr);
                         $exam->setCourseId($courseCode);
                         $exam->setFilePath($this->_dir . $file);
                         $exam->setYear($this->_year);
                         $exam->save();
                     }
                 }
             }
             if ($err) {
                 $errArr[] = $file;
             }
         }
     }
     closedir($handler);
     return $errArr;
 }
Example #24
0
    $employeeInfo = $employee->getEmployeeInfoById($employeeId);
    return View::make('admin.departmentnew', ['employeeInfo' => $employeeInfo]);
}));
//CREATE: NEW DEPARTMENT
Route::post('/admin/department/new', array('as' => 'adminProcessNewDepartment', 'uses' => function () {
    //return 'Save New Department';
    $data = Input::all();
    $rules = array('department_name' => 'required');
    $validator = Validator::make($data, $rules);
    if ($validator->fails()) {
        $messages = $validator->messages();
        return Redirect::to('/admin/department/new')->withErrors($validator);
    } else {
        $department = new Department();
        $department->name = trim(ucwords($data['department_name']));
        if ($department->save()) {
            $message = 'Created Successfully.';
            return Redirect::to('/admin/department/new')->with('message', $message);
        }
    }
}));
//UPDATE: EXISTING DEPARTMENT
Route::get('/admin/department/edit/{id}', array('as' => 'adminEditDepartment', 'uses' => function ($id) {
    $id = (int) $id;
    $employeeId = Session::get('userEmployeeId');
    $userId = Session::get('userId');
    $employee = new Employee();
    $employeeInfo = $employee->getEmployeeInfoById($employeeId);
    //return 'Update Department';
    return View::make('admin.departmentedit', array('id' => $id, 'employeeInfo' => $employeeInfo));
}));
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionImport()
 {
     $model = new Department();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Department'])) {
         if (!empty($_FILES)) {
             $tempFile = $_FILES['Department']['tmp_name']['fileImport'];
             $fileTypes = array('xls', 'xlsx');
             // File extensions
             $fileParts = pathinfo($_FILES['Department']['name']['fileImport']);
             if (in_array(@$fileParts['extension'], $fileTypes)) {
                 Yii::import('ext.heart.excel.EHeartExcel', true);
                 EHeartExcel::init();
                 $inputFileType = PHPExcel_IOFactory::identify($tempFile);
                 $objReader = PHPExcel_IOFactory::createReader($inputFileType);
                 $objPHPExcel = $objReader->load($tempFile);
                 $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
                 $baseRow = 2;
                 $inserted = 0;
                 $read_status = false;
                 while (!empty($sheetData[$baseRow]['A'])) {
                     $read_status = true;
                     //$department_id=  $sheetData[$baseRow]['A'];
                     $name = $sheetData[$baseRow]['B'];
                     $model2 = new Department();
                     //$model2->department_id=  $department_id;
                     $model2->name = $name;
                     try {
                         if ($model2->save()) {
                             $inserted++;
                         }
                     } catch (Exception $e) {
                         Yii::app()->user->setFlash('error', "{$e->getMessage()}");
                         //$this->refresh();
                     }
                     $baseRow++;
                 }
                 Yii::app()->user->setFlash('success', $inserted . ' row inserted');
             } else {
                 Yii::app()->user->setFlash('warning', 'Wrong file type (xlsx, xls, and ods only)');
             }
         }
         $this->render('admin', array('model' => $model));
     } else {
         $this->render('admin', array('model' => $model));
     }
 }
 public function save_department()
 {
     $id = Input::get('id');
     $store_id = Input::get('store_id');
     $department = Department::find($id);
     if (!$department) {
         $department = new Department();
     }
     $department->name = Input::get('name');
     $department->store_id = $store_id;
     $department->save();
     $message = "Successfully updated the department";
     $type = "success";
     return Redirect::to('/admin/store/' . $store_id . '/departments')->with('type', $type)->with('message', $message);
 }
    }
    $c->save();
    echo "Category: {$c->getName()}\n";
}
// Now that we've got People and Categories in the database,
// Link the Departments with their Categories and Default Person
$result = $mongo->departments->find();
foreach ($result as $r) {
    $d = new Department($r['name']);
    if (!empty($r['defaultPerson']['_id'])) {
        $id = getPersonIdFromCrosswalk($r['defaultPerson']['_id']);
        $d->setDefaultPerson_id($id);
    }
    if (!empty($r['categories'])) {
        $ids = array();
        foreach ($r['categories'] as $c) {
            try {
                $category = new Category($c['name']);
                $ids[] = $category->getId();
            } catch (Exception $e) {
                // Departments may have old categories we have deleted
                // Just ignore them
            }
        }
        $d->setCategories($ids);
    }
    $d->save();
    $p = $d->getDefaultPerson();
    $p = $p ? $p->getFullname() : '';
    echo "Department: {$d->getName()} Person: {$p}\n";
}
 function processvariablesAction()
 {
     $session = SessionWrapper::getInstance();
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); // exit;
     if (isArrayKeyAnEmptyString('noreload', $formvalues)) {
         $hasnoreload = false;
     } else {
         $hasnoreload = true;
     }
     $haserror = false;
     if (isArrayKeyAnEmptyString('value', $formvalues) && !$hasnoreload) {
         $haserror = true;
         $session->setVar(ERROR_MESSAGE, 'Error: No value specified for addition');
         $session->setVar(FORM_VALUES, $formvalues);
         $this->_helper->redirector->gotoUrl($this->view->baseUrl('config/variables/' . $formvalues['lookupid']));
     }
     $successurl = $this->view->baseUrl('config/variables/type/' . $formvalues['lookupid']);
     $type_ext = '';
     $alias = '';
     if (!isArrayKeyAnEmptyString('alias', $formvalues)) {
         $alias = trim($formvalues['alias']);
         if ($alias == 'undefined') {
             $alias = '';
         }
     }
     if ($formvalues['lookupid'] == 7) {
         $alias = decode($formvalues['alias']);
         if (isArrayKeyAnEmptyString('id', $formvalues)) {
             $alias = $formvalues['alias'];
         }
     }
     // exit;
     // debugMessage()
     switch ($formvalues['lookupid']) {
         case 9:
             $formvalues['defaultamount'] = $formvalues['alias'];
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $formvalues['defaultamount'] = decode($formvalues['alias']);
             }
             $formvalues['amounttype'] = $formvalues['alias2'];
             $formvalues['name'] = decode(trim($formvalues['value']));
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $formvalues['name'] = $formvalues['name'];
             }
             $formvalues['companyid'] = getCompanyID();
             $benefittype = new BenefitType();
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $benefittype->populate($formvalues['id']);
                 $formvalues['lastupdatedby'] = $session->getVar('userid');
             } else {
                 $formvalues['createdby'] = $session->getVar('userid');
             }
             $benefittype->processPost($formvalues);
             /* debugMessage($benefittype->toArray());
             			debugMessage('errors are '.$benefittype->getErrorStackAsString()); exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($benefittype->hasError()) {
                 $session->setVar(ERROR_MESSAGE, $benefittype->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $benefittype->getErrorStackAsString();
             } else {
                 try {
                     $benefittype->save();
                     // debugMessage($benefittype->toArray()); exit;
                     $result = array('id' => $benefittype->getID(), 'name' => $benefittype->getName(), 'alias' => $benefittype->getdefaultamount(), 'alias2' => $benefittype->getamounttype());
                     $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $benefittype->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                     $result['error'] = $benefittype->getErrorStackAsString();
                 }
             }
             break;
         case 11:
             $formvalues['name'] = trim($formvalues['value']);
             $department = new Department();
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $department->populate($formvalues['id']);
                 $formvalues['lastupdatedby'] = $session->getVar('userid');
             } else {
                 $formvalues['createdby'] = $session->getVar('userid');
             }
             $formvalues['companyid'] = getCompanyID();
             $department->processPost($formvalues);
             /* debugMessage($department->toArray());
             			debugMessage('errors are '.$department->getErrorStackAsString()); // exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($department->hasError()) {
                 $session->setVar(ERROR_MESSAGE, $department->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $department->getErrorStackAsString();
             } else {
                 try {
                     $department->save();
                     $result = array('id' => $department->getID(), 'name' => $department->getName(), 'error' => '');
                     $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $department->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                     $result['error'] = $department->getErrorStackAsString();
                 }
             }
             break;
         default:
             $lookupvalue = new LookupTypeValue();
             $lookuptype = new LookupType();
             $lookuptype->populate($formvalues['lookupid']);
             $index = '';
             if ($hasnoreload) {
                 $index = $lookuptype->getNextInsertIndex();
                 $value = trim($formvalues['value']);
             } else {
                 if (!isArrayKeyAnEmptyString('index', $formvalues)) {
                     $index = $formvalues['index'];
                 } else {
                     $index = $lookuptype->getNextInsertIndex();
                 }
                 $value = addslashes(decode(trim($formvalues['value'])));
             }
             $dataarray = array('id' => $formvalues['id'], 'lookuptypeid' => $formvalues['lookupid'], 'lookuptypevalue' => $index, 'lookupvaluedescription' => $value, 'alias' => $alias, 'createdby' => $session->getVar('userid'), 'companyid' => getCompanyID());
             // debugMessage($dataarray);
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $lookupvalue->populate($formvalues['id']);
                 $beforesave = $lookupvalue->toArray();
                 // debugMessage($beforesave);
             }
             // unset($dataarray['id']);
             $lookupvalue->processPost($dataarray);
             /* debugMessage($lookupvalue->toArray());
               	debugMessage('errors are '.$lookupvalue->getErrorStackAsString()); exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($lookupvalue->hasError()) {
                 $haserror = true;
                 $session->setVar(ERROR_MESSAGE, $lookupvalue->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $lookupvalue->getErrorStackAsString();
             } else {
                 try {
                     $lookupvalue->save();
                     if (!$hasnoreload) {
                         $url = $this->view->serverUrl($this->view->baseUrl("config/variables/lookupid/" . $formvalues['lookupid']));
                         $module = '0';
                         if (isArrayKeyAnEmptyString('id', $formvalues)) {
                             $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                             $type = SYSTEM_ADDVARIABLE;
                             $usecase = '0.1';
                             $details = 'Variable - <b>' . $lookupvalue->getlookupvaluedescription() . ' </b>(' . $lookupvalue->getLookupType()->getdisplayname() . ') addded';
                         } else {
                             $session->setVar(SUCCESS_MESSAGE, "Successfully updated");
                             $type = SYSTEM_UPDATEVARIABLE;
                             $usecase = '0.2';
                             $details = 'Variable - <b>' . $lookupvalue->getlookupvaluedescription() . ' </b>(' . $lookupvalue->getLookupType()->getdisplayname() . ') updated';
                             $prejson = json_encode($beforesave);
                             $lookupvalue->clearRelated();
                             $after = $lookupvalue->toArray();
                             // debugMessage($after);
                             $postjson = json_encode($after);
                             // debugMessage($postjson);
                             $diff = array_diff($beforesave, $after);
                             // debugMessage($diff);
                             $jsondiff = json_encode($diff);
                             // debugMessage($jsondiff);
                         }
                         $browser = new Browser();
                         $audit_values = $session->getVar('browseraudit');
                         $audit_values['module'] = $module;
                         $audit_values['usecase'] = $usecase;
                         $audit_values['transactiontype'] = $type;
                         $audit_values['status'] = "Y";
                         $audit_values['userid'] = $session->getVar('userid');
                         $audit_values['transactiondetails'] = $details;
                         $audit_values['url'] = $url;
                         if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                             $audit_values['isupdate'] = 1;
                             $audit_values['prejson'] = $prejson;
                             $audit_values['postjson'] = $postjson;
                             $audit_values['jsondiff'] = $jsondiff;
                         }
                         // debugMessage($audit_values);
                         $this->notify(new sfEvent($this, $type, $audit_values));
                     }
                     $result = array('id' => $lookupvalue->getlookuptypevalue(), 'name' => $lookupvalue->getlookupvaluedescription(), 'alias' => $lookupvalue->getalias(), 'error' => '');
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $lookupvalue->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                 }
             }
             break;
     }
     // debugMessage($successurl);exit();
     if (!$hasnoreload) {
         $this->_helper->redirector->gotoUrl($successurl);
     } else {
         echo json_encode($result);
     }
 }
 function test_getCourses()
 {
     //Arrange
     $test_department = new Department("Biology", "346 Stupid Avenue");
     $test_department->save();
     $name = "History 0001";
     $code = "HS001";
     $test_course = new Course($name, $code, $test_department->getId());
     $test_course->save();
     $name2 = "Dogs 101";
     $code2 = "DW101";
     $test_course2 = new Course($name2, $code2, $test_department->getId());
     $test_course2->save();
     //Act
     $result = $test_department->getCourses();
     //Assert
     $this->assertEquals([$test_course, $test_course2], $result);
 }
Example #30
0
 public function actionSavedepartment()
 {
     $organid = $this->Getorganid();
     if (empty($_POST['departid'])) {
         $department = new Department();
         $department->DepartmentName = $_POST['departmentName'];
         $department->ParentID = $_POST['parentID'];
         $department->Describe = $_POST['describe'];
         $department->OrganID = $organid['OrganID'];
         $department->UserID = Yii::app()->user->id;
         $department->CreateTime = time();
         $result = $department->save();
     } else {
         $department = Department::model()->findByPk($_POST['departid']);
         $department->DepartmentName = $_POST['departmentName'];
         $department->ParentID = $_POST['parentID'];
         $department->Describe = $_POST['describe'];
         $department->UserID = Yii::app()->user->id;
         $department->UpdateTime = time();
         $result = $department->save();
     }
     if ($result) {
         $message = "保存成功";
     } else {
         $message = "保存失败";
     }
     echo json_encode($message);
 }