Ejemplo n.º 1
0
 /**
  * Import clients details from CSV files
  *
  * @param sfWebRequest $request
  */
 public function executeImportclients($request)
 {
     $user = $this->getUser();
     $column_heading = array();
     $data_rows = array();
     $import_info = $request->getParameter('import');
     $email_notification = true;
     $is_header_row = (bool) $import_info['header_row'];
     $this->errors = array();
     $this->passed = '';
     $this->failed = '';
     $this->_branch = $request->getParameter('_bid', 0);
     if ($user->hasAttribute($this->upload_attribute)) {
         $filename = $user->getAttribute($this->upload_attribute);
         $csv_importer = new CSVImporter();
         $success_message = sfConfig::get('mod_client_upload_message');
         $column_heading = $csv_importer->readCSVColumns($filename, $success_message);
         $data_rows = $csv_importer->readCSVColumns($filename, '', false);
     }
     $this->column_heading = $column_heading;
     $this->data_rows = $data_rows;
     $form_data = $request->getParameter('field_name');
     if ($form_data && $user->hasAttribute($this->upload_attribute)) {
         $filename = $user->getAttribute($this->upload_attribute);
         $user->getAttributeHolder()->remove($this->upload_attribute);
         $this->column_heading = array();
         $csv_importer = new CSVImporter($user, CSVImporter::IMPORT_CLIENTS);
         $response = $csv_importer->saveCSVFileData($filename, $form_data, $is_header_row, $email_notification);
         if (empty($response[0])) {
             $this->redirect('client/index');
         } else {
             $this->errors = $response[0];
             $this->passed = $response[1];
             $this->failed = $response[2];
         }
     }
     $this->file_attribute = $this->upload_attribute;
 }