public function setup()
 {
     $rules = array('first_name' => 'required|alpha_num|max:128', 'last_name' => 'required|alpha_num|max:128', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:7|confirmed', 'sitename' => 'required|max:50');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages());
     } else {
         $setting = new Setting();
         $setting->sitename = Input::get('sitename');
         $setting->save();
         $list = new Addressbook();
         $list->name = 'General';
         $list->save();
         try {
             $user = Sentry::register(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')), true);
             $feedback = array('success' => 'Great! Your system is ready to roll! You will be redirected to login form in 3 seconds.');
             return Response::json($feedback);
         } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
             echo 'Login field is required.';
         } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
             echo 'Password field is required.';
         } catch (Cartalyst\Sentry\Users\UserExistsException $e) {
             echo 'User with this login already exists.';
         }
     }
 }
 public function add_new_list()
 {
     $rules = array('name' => 'required|max:128|unique:lists', 'active' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Response::json($validator->messages());
     } else {
         $name = Input::get('name');
         $active = Input::get('active');
         $list = new Addressbook();
         $list->name = $name;
         $list->active = $active;
         $list->save();
         return Response::json(array('success' => 'New list successfully saved'));
     }
 }
 public function store()
 {
     $inputs = [];
     foreach (Input::all() as $key => $input) {
         $inputs[$key] = Jamesy\Sanitiser::trimInput($input);
     }
     $validation = Jamesy\MyValidations::validate($inputs, $this->rules);
     if ($validation != NULL) {
         return Redirect::back()->withErrors($validation)->withInput();
     } else {
         $addressbook = new Addressbook();
         $addressbook->name = $inputs['name'];
         if (Input::get('active') == '0' || Input::get('active') == '1') {
             $addressbook->active = Input::get('active');
         }
         $addressbook->save();
         return Redirect::to('dashboard/lists')->withSuccess('New list created.');
     }
 }
Esempio n. 4
0
 /**
  * Get the addressbook for the user profiles. If it doesn't exist it will be
  * created.
  * 
  * @return Addressbook 
  */
 public function getUsersAddressbook()
 {
     $ab = Addressbook::model()->findSingleByAttribute('users', '1');
     //\GO::t('users','base'));
     if (!$ab) {
         $ab = new Addressbook();
         $ab->name = \GO::t('users');
         $ab->users = true;
         $ab->save();
         $ab->acl->addGroup(\GO::config()->group_internal);
     }
     return $ab;
 }
 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 = $this->loadModel((int) $data[0]);
                     if ($model === null) {
                         $model = new Addressbook();
                     }
                     $model->fullname = $data[1];
                     $model->iscustomer = (int) $data[2];
                     $model->isemployee = (int) $data[3];
                     $model->isapplicant = (int) $data[4];
                     $model->isvendor = (int) $data[5];
                     $model->isinsurance = (int) $data[6];
                     $model->isbank = (int) $data[7];
                     $model->ishospital = (int) $data[8];
                     $model->iscatering = (int) $data[9];
                     $model->recordstatus = (int) $data[10];
                     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;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     parent::actionCreate();
     $this->lookupdata();
     $ab = new Addressbook();
     $ab->recordstatus = 1;
     $ab->isemployee = 1;
     $ab->fullname = 'fullname';
     $ab->save();
     $model = new Employee();
     $model->fullname = 'fullname';
     $model->addressbookid = $ab->addressbookid;
     if (Yii::app()->request->isAjaxRequest) {
         if ($model->save()) {
             echo CJSON::encode(array('status' => 'success', 'employeeid' => $model->employeeid, 'divcreate' => $this->renderPartial('_form', array('model' => $model, 'employeeaddress' => $this->employeeaddress, 'employeeeducation' => $this->employeeeducation, 'employeeinformal' => $this->employeeinformal, 'employeewo' => $this->employeewo, 'employeefamily' => $this->employeefamily), true)));
             Yii::app()->end();
         }
     }
 }