/** Add new staff member
  */
 public function addAction()
 {
     $form = new ContactForm();
     $form->submit->setLabel('Add a new Scheme contact');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
             $coords = $this->_geocoder->getCoordinates($address);
             if ($coords) {
                 $lat = $coords['lat'];
                 $long = $coords['lon'];
                 $pm = new Pas_Service_Geoplanet();
                 $place = $pm->reverseGeoCode($lat, $lon);
                 $woeid = $place['woeid'];
             } else {
                 $lat = NULL;
                 $lon = NULL;
                 $woeid = NULL;
             }
             $insertData = array('firstname' => $form->getValue('firstname'), 'lastname' => $form->getValue('lastname'), 'role' => $form->getValue('role'), 'dbaseID' => $form->getValue('dbaseID'), 'email_one' => $form->getValue('email_one'), 'email_two' => $form->getValue('email_two'), 'address_1' => $form->getValue('address_1'), 'address_2' => $form->getValue('address_2'), 'region' => $form->getValue('region'), 'town' => $form->getValue('town'), 'county' => $form->getValue('county'), 'postcode' => $form->getValue('postcode'), 'country' => $form->getValue('country'), 'identifier' => $form->getValue('identifier'), 'telephone' => $form->getValue('telephone'), 'fax' => $form->getValue('fax'), 'website' => $form->getValue('website'), 'profile' => $form->getValue('profile'), 'alumni' => $form->getValue('alumni'), 'created' => $this->getTimeForForms(), 'createdBy' => $this->getIdentityForForms(), 'latitude' => $lat, 'longitude' => $lon, 'woeid' => $woeid);
             foreach ($insertData as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($insertData[$key]);
                 }
             }
             $contacts = new Contacts();
             $insert = $contacts->insert($insertData);
             $this->_flashMessenger->addMessage('Scheme contact created!');
             $this->_redirect($this->_redirectUrl . 'contact/id/' . $insert);
         } else {
             $form->populate($formData);
         }
     }
 }
示例#2
0
 /**
  * function to map related to (contacts) for potentials while importing
  * checks if the contact exists else adds a new contact
  * @param string $contact_name
  * @return integer idcontacts
  */
 public function map_related_to_contacts($contact_name)
 {
     if (strlen($contact_name) > 2) {
         $contact_name = trim($contact_name);
         $do_contact = new Contacts();
         $qry = "\n\t\t\tselect `idcontacts`\n\t\t\tfrom  `contacts`\n\t\t\twhere `deleted` = 0 \n\t\t\tAND iduser = "******"do_user"]->iduser . "\n\t\t\tAND \n\t\t\t(\n\t\t\t\tconcat(firstname,' ',lastname) = ?\n\t\t\t\tor\n\t\t\t\tconcat(lastname,' ',firstname) = ?\n\t\t\t)\n\t\t\t";
         $do_contact->query($qry, array($contact_name, $contact_name));
         if ($do_contact->getNumRows() > 0) {
             $do_contact->next();
             return $do_contact->idcontacts;
         } else {
             $contact_name_explode = explode(" ", $contact_name);
             $do_contact->insert("contacts", array("firstname" => CommonUtils::purify_input($contact_name_explode[0]), "lastname" => CommonUtils::purify_input($contact_name_explode[1]), "iduser" => $_SESSION["do_user"]->iduser));
             $idcontacts = $do_contact->getInsertId();
             //adding the added_on
             $q_upd = "\n\t\t\t\tupdate `contacts` \n\t\t\t\tset `added_on` = '" . date("Y-m-d H:i:s") . "'\n\t\t\t\twhere `idcontacts` = " . $idcontacts;
             $do_contact->query($q_upd);
             $do_contact->insert("contacts_custom_fld", array("idcontacts" => $idcontacts));
             $do_contact->insert("contacts_address", array("idcontacts" => $idcontacts));
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idcontacts, 4, 'add');
             $do_data_history->free();
             return $idcontacts;
         }
     }
 }