Пример #1
0
 public function init()
 {
     parent::init();
     if (!\Yii::$app->user->can('adm')) {
         if (!\Yii::$app->request->isAjax) {
             \Yii::$app->getResponse()->redirect('/login?err=1');
         } else {
             Core::error('У Вас нет прав на контроллер');
             Core::encode_echo();
         }
     }
 }
Пример #2
0
 public function init()
 {
     parent::init();
     // TODO: Change the autogenerated stub
     if (!\Yii::$app->user->can('adm_hosp')) {
         if (!\Yii::$app->request->isAjax) {
             \Yii::$app->getResponse()->redirect('/login?err=1');
         } else {
             Core::error('У Вас нет прав на контроллер');
             Core::encode_echo();
         }
     }
 }
Пример #3
0
 public function init()
 {
     parent::init();
     // TODO: Change the autogenerated stub
     if (!\Yii::$app->user->can('doctor_user')) {
         if (!\Yii::$app->request->isAjax) {
             \Yii::$app->getResponse()->redirect('/login?err=1');
         } else {
             Core::error('У Вас нет прав на контроллер');
             Core::encode_echo();
         }
     }
     $this->_user = Doctor::getInstance()->get(\Yii::$app->user->id);
 }
Пример #4
0
 public function set()
 {
     $this->id = $this->id > 0 ? $this->id : null;
     $this->doctor_id = $this->doctor_id > 0 ? $this->doctor_id : null;
     $this->hosp_id = $this->hosp_id > 0 ? $this->hosp_id : null;
     if ($this->phone != '') {
         $this->phone = preg_replace('/[^0-9]/', '', $this->phone);
         $cnt = mb_strlen($this->phone);
         if ($cnt != 11) {
             Core::error("Поле <strong>Телефон</strong> должно состоять из 10 цифр + код страны", 'phone');
         }
     }
     $this->fld_name['hosp_id'] = 'Больница';
     $this->fld_name['dt_bd_format'] = 'День рождения';
     $ar = ['name_f' => 'req', 'name_i' => 'req', 'name_o' => 'req', 'dt_bd_format' => 'req', 'hosp_id' => 'req'];
     $this->validate_ar($ar);
     if (Core::hasError() === true) {
         return;
     }
     list($d, $m, $Y) = explode('.', $this->dt_bd_format);
     $this->dt_bd = Core::format_date($Y, $m, $d, 'Y-m-d');
     if ($this->pas_kogda_dt_format != '') {
         list($d, $m, $Y) = explode('.', $this->pas_kogda_dt_format);
         $this->pas_kogda_dt = Core::format_date($Y, $m, $d, 'Y-m-d');
     } else {
         $this->pas_kogda_dt = null;
     }
     $fld = $params = [];
     $fld['hosp_id'] = $this->hosp_id;
     $fld['doctor_id'] = $this->doctor_id;
     $fld['name_f'] = $this->name_f;
     $fld['name_i'] = $this->name_i;
     $fld['name_o'] = $this->name_o;
     $fld['phone'] = $this->phone;
     $fld['dt_bd'] = $this->dt_bd;
     $fld['add_oblast_id'] = $this->add_oblast_id;
     $fld['add_city_id'] = $this->add_city_id;
     $fld['add_street'] = $this->add_street;
     $fld['add_d'] = $this->add_d;
     $fld['add_k'] = $this->add_k;
     $fld['add_kv'] = $this->add_kv;
     $fld['pas_ser'] = $this->pas_ser;
     $fld['pas_num'] = $this->pas_num;
     $fld['pas_kem'] = $this->pas_kem;
     $fld['pas_kogda_dt'] = $this->pas_kogda_dt;
     $fld['pas_add_oblast_id'] = $this->pas_add_oblast_id;
     $fld['pas_add_city_id'] = $this->pas_add_city_id;
     $fld['pas_add_street'] = $this->pas_add_street;
     $fld['pas_add_d'] = $this->pas_add_d;
     $fld['pas_add_k'] = $this->pas_add_k;
     $fld['pas_add_kv'] = $this->pas_add_kv;
     $fld['ank_soc'] = $this->ank_soc;
     $fld['ank_obraz'] = $this->ank_obraz;
     $fld['ank_sem'] = $this->ank_sem;
     $fld['ank_d'] = $this->ank_d;
     $fld['ank_like'] = $this->ank_like;
     foreach ($this->var_vred['data'] as $key => $item) {
         $fld['vred_' . $key] = $this->vred[$key];
     }
     foreach ($this->var_prof['data'] as $key => $item) {
         $fld['prof_' . $key] = $this->prof[$key];
     }
     $fld['prof_month'] = $this->prof_month;
     if ($this->id === null) {
         $fld_auth = [];
         $fld_auth['t'] = 'mam';
         $fld_auth['role'] = null;
         \yii::$app->db->createCommand()->insert('auth', $fld_auth)->execute();
         $this->id = \yii::$app->db->getLastInsertID('auth_id_seq');
         $fld['auth_id'] = $this->id;
         \yii::$app->db->createCommand()->insert('auth_mam', $fld)->execute();
     } else {
         $params['auth_id'] = $this->id;
         $where = 'auth_id=:auth_id';
         \yii::$app->db->createCommand()->update('auth_mam', $fld, $where, $params)->execute();
     }
 }
Пример #5
0
 /**
  * @param $fld - название поля
  * @param $par - типпроверки
  * @param bool|true $add_err записывать в массив ошибок или нет
  * @return bool
  */
 protected function validate($fld, $par, $add_err = true)
 {
     $name = $this->fld_name[$fld];
     $ret = true;
     switch ($par) {
         case 'req':
             if ($this->{$fld} == '') {
                 $ret = false;
                 if ($add_err === true) {
                     Core::error('Поле <strong>"' . $name . '"</strong> обязательно к заполнению', $fld);
                 }
             }
             break;
         case 'email':
             $validator = new EmailValidator();
             if (!$validator->validate($this->{$fld})) {
                 $ret = false;
                 if ($add_err === true) {
                     Core::error('Некорректный email - <strong>' . $name . '</strong>', $fld);
                 }
             }
             break;
     }
     return $ret;
 }
Пример #6
0
 public function set()
 {
     $this->id = $this->id > 0 ? $this->id : null;
     $this->role = $this->role != '' ? $this->role : null;
     if ($this->email == '') {
         Core::error("Поле <strong>E-mail</strong> обязательно к заполнению", 'email');
     } else {
         $sql = 'Select count(*) from auth_adm where email=:email and (auth_id<>:id or :id is null)';
         $params = [];
         $params['email'] = $this->email;
         $params['id'] = $this->id;
         $cnt = \yii::$app->db->createCommand($sql, $params)->queryScalar();
         if ($cnt > 0) {
             Core::error('E-mail <strong>"' . $this->email . '"</strong> уже есть в базе', 'email');
         } else {
             $EmailValidator = new \yii\validators\EmailValidator();
             if (!$EmailValidator->validate($this->email)) {
                 Core::error('Некорректное поле <strong>"E-mail"</strong>', 'email');
             }
         }
     }
     if ($this->pw == '') {
         Core::error("Поле <strong>Пароль</strong> обязательно к заполнению", 'pw');
     }
     if ($this->name_f == '') {
         Core::error("Поле <strong>ФАМИЛИЯ</strong> обязательно к заполнению", 'name_f');
     }
     if ($this->name_i == '') {
         Core::error("Поле <strong>ИМЯ</strong> обязательно к заполнению", 'name_i');
     }
     if (Core::hasError() === true) {
         return;
     }
     $transaction = \yii::$app->db->getTransaction();
     if (!$transaction) {
         $transaction = \Yii::$app->db->beginTransaction();
     }
     try {
         if ($this->id === null) {
             $fld = [];
             $fld['t'] = 'adm';
             $fld['role'] = $this->role;
             \yii::$app->db->createCommand()->insert('auth', $fld)->execute();
             $this->id = \yii::$app->db->getLastInsertID('auth_id_seq');
             $fld = [];
             $fld['auth_id'] = $this->id;
             $fld['email'] = $this->email;
             $fld['pw'] = $this->pw;
             $fld['name_f'] = $this->name_f;
             $fld['name_i'] = $this->name_i;
             $fld['name_o'] = $this->name_o;
             \yii::$app->db->createCommand()->insert('auth_adm', $fld)->execute();
         } else {
             $this->upd_role($this->id, $this->role);
             $fld = $params = [];
             $fld['pw'] = $this->pw;
             $fld['name_f'] = $this->name_f;
             $fld['name_i'] = $this->name_i;
             $fld['name_o'] = $this->name_o;
             $params['auth_id'] = $this->id;
             $where = 'auth_id=:auth_id';
             \yii::$app->db->createCommand()->update('auth_adm', $fld, $where, $params)->execute();
         }
         $this->upd_perm($this->id, $this->perm);
         if (\app\component\Core::hasError() === false) {
             $transaction->commit();
         } else {
             $transaction->rollBack();
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }