예제 #1
0
 public function update_profile()
 {
     $ObjContactsTemp = new contactsTempModel();
     $ObjContacts = new contactsModel();
     $loggin_user = $ObjContacts->get_loggin_user_info();
     $contact_id = $loggin_user->contact_id;
     $status = isset($loggin_user->cont_status) ? $loggin_user->cont_status : '';
     $company_id = Input::get('company_id');
     $firstname = Input::get('firstname');
     $lastname = Input::get('lastname');
     $midini = Input::get('midini');
     $email = Input::get('email');
     $address1 = Input::get('address1');
     $address2 = Input::get('address2');
     $city = Input::get('city');
     $zipcode = Input::get('zipcode');
     $secret_question = Input::get('secret_question');
     $secret_answer = Input::get('secret_answer');
     $phone = Input::get('phone');
     $use_company_address = Input::get('use_company_address');
     $password = Input::get('password');
     $password_confirm = Input::get('password_confirm');
     $data = array('first_name' => $firstname, 'last_name' => $lastname, 'midini' => $midini, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'zipcode' => $zipcode, 'secret_question' => $secret_question, 'secret_answer' => $secret_answer, 'office_phone' => $phone, 'use_company_address' => $use_company_address);
     if ($password && $password_confirm) {
         if ($password != $password_confirm) {
             $error_msg = 'Confirm password must equal to Password';
         } else {
             $data['password'] = $password;
         }
     }
     //$contact_status = Session::get('contact_status');
     //if( $contact_status == 'Contact Temp' ){
     if ($status == 'Contact Temp') {
         $result = $ObjContactsTemp->update_data($data, $contact_id);
     } else {
         $result = $ObjContacts->update_data($data, $contact_id);
     }
     if ($result) {
         $message = 'Update Contact profile successful.';
     } else {
         $message = 'Update Contact profile not successful.';
     }
     //if( $contact_status == 'Contact Temp'  && $company_id != ''&& $firstname != '' && $lastname != '' && $email != '' && $city != '' && $zipcode != '' && $phone != '' ){
     if ($status == 'Contact Temp' && $company_id != '' && $firstname != '' && $lastname != '' && $email != '' && $city != '' && $zipcode != '' && $phone != '') {
         $contcol = $ObjContactsTemp->get_record_by_id($contact_id);
         $data = array('paskr_company_id' => $contcol->company_id, 'company_id' => $contcol->company_id, 'email_address' => $contcol->email_address, 'first_name' => $contcol->first_name, 'last_name' => $contcol->last_name, 'midini' => $contcol->midini, 'address1' => $contcol->address1, 'address2' => $contcol->address2, 'city' => $contcol->city, 'zipcode' => $contcol->zipcode, 'secret_question' => $contcol->secret_question, 'secret_answer' => $contcol->secret_answer, 'office_phone' => $contcol->office_phone, 'use_company_address' => $contcol->use_company_address);
         $new_contact_id = $ObjContacts->insert_data($data);
         if ($new_contact_id) {
             $result = $ObjContactsTemp->delete_data(array('`contact_id`=' => $contact_id));
             Session::put('contact_id', $new_contact_id);
             //Session::put('contact_status','Contact Final');
             $message = 'Update Contact profile successful.';
             return Redirect::to('upload_contacts')->with('message', $message);
         }
     }
     return Redirect::to('profile')->with('message', $message);
 }
 public function uploaded_contacts_save($cuf_id)
 {
     $ObjContacts = new contactsModel();
     $ObjCompanies = new companiesModel();
     $ObjCUF = new contactsUploadedFileModel();
     $ObjCUFF = new contactsUploadedFileFieldsModel();
     $result = FALSE;
     $uploaded_file_col = $this->get_record_join(array('`j1`.`cuf_id`=' => $cuf_id));
     $contact_id = $uploaded_file_col->contact_id;
     $cuff_rows = $ObjCUFF->get_records(array('`cuf_id`=' => $cuf_id));
     $header_format = $this->get_fieldname_column($cuff_rows);
     $where_params = array('`cuf_id`=' => $cuf_id);
     $order_params = array('ASC' => 'cut_id');
     $uploaded_contacts_rows = $this->get_records($where_params, $order_params);
     if ($uploaded_contacts_rows) {
         foreach ($uploaded_contacts_rows as $col) {
             $cut_id = $col->cut_id;
             $this->update_uploaded_contacts_value($cuff_rows, $cut_id);
         }
     }
     $where_params = array('`cuf_id`=' => $cuf_id);
     $order_params = array('ASC' => 'cut_id');
     $uploaded_contacts_rows = $this->get_records($where_params, $order_params);
     if ($uploaded_contacts_rows) {
         foreach ($uploaded_contacts_rows as $col) {
             $cut_id = $col->cut_id;
             $error_message = $col->cut_error_message;
             $email_address = $this->get_header_column_value_by_fieldname('email_address', $col, $header_format);
             $last_name = $this->get_header_column_value_by_fieldname('last_name', $col, $header_format);
             $first_name = $this->get_header_column_value_by_fieldname('first_name', $col, $header_format);
             $address1 = $this->get_header_column_value_by_fieldname('address1', $col, $header_format);
             $city = $this->get_header_column_value_by_fieldname('city', $col, $header_format);
             $state_code = $this->get_header_column_value_by_fieldname('state_code', $col, $header_format);
             $zipcode = $this->get_header_column_value_by_fieldname('zipcode', $col, $header_format);
             $company_id = '';
             $company = $this->get_header_column_value_by_fieldname('company', $col, $header_format);
             if ($company) {
                 $company_id = $ObjCompanies->save_company_if_company_dont_exist($company, $address1, $city, $state_code, $zipcode);
             }
             if ($error_message == '') {
                 $last_name = $last_name ? $last_name : 'Department';
                 $first_name = $first_name ? $first_name : 'Estimating';
                 $data = array('contact_id_assigned' => $contact_id, 'email_address' => $email_address, 'last_name' => $last_name, 'first_name' => $first_name, 'company_id' => $company_id, 'address1' => $address1, 'city' => $city, 'state_code' => $state_code, 'zipcode' => $zipcode);
                 $cid = $ObjContacts->insert_data($data);
                 if ($cid) {
                     $this->delete_data(array('`cut_id`=' => $cut_id));
                 }
             }
         }
     }
     $count_contacts = $this->get_records(array('`cuf_id`=' => $cuf_id));
     if ($count_contacts == FALSE) {
         $result = TRUE;
     }
     return $result;
 }