Exemple #1
0
 public function copyAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $id = $this->_getParam('id', 0);
     $contact = new Contacts_Model_DbTable_Contact();
     $data = $contact->getContact($id);
     unset($data['id']);
     unset($data['street'], $data['postcode'], $data['city'], $data['country'], $data['shippingname1'], $data['shippingname2'], $data['shippingdepartment'], $data['shippingstreet'], $data['shippingpostcode'], $data['shippingcity'], $data['shippingcountry'], $data['shippingphone']);
     $data['name1'] = $data['name1'] . ' 2';
     $data['created'] = $this->_date;
     $data['createdby'] = $this->_user['id'];
     $data['modified'] = '0000-00-00';
     $data['modifiedby'] = 0;
     echo $contactid = $contact->addContact($data);
     $addressDb = new Application_Model_DbTable_Address();
     //Primary Address
     $primaryAddress = $addressDb->fetchRow($addressDb->select()->where('contactid = ?', $id)->where('type = ?', 'primaryAddress')->where('clientid = ?', $this->_user['clientid']));
     $street = $primaryAddress['street'];
     $postcode = $primaryAddress['postcode'];
     $city = $primaryAddress['city'];
     $country = $primaryAddress['country'];
     $addressDb->addAddress($contactid, 'primaryAddress', '', '', '', $street, $postcode, $city, $country, '', $this->_user['clientid'], $this->_date);
     //Shipping Address
     $shippingAddress = $addressDb->fetchRow($addressDb->select()->where('contactid = ?', $id)->where('type = ?', 'shippingAddress')->where('clientid = ?', $this->_user['clientid']));
     $shippingname1 = $shippingAddress['name1'];
     $shippingname2 = $shippingAddress['name2'];
     $shippingdepartment = $shippingAddress['department'];
     $shippingstreet = $shippingAddress['street'];
     $shippingpostcode = $shippingAddress['postcode'];
     $shippingcity = $shippingAddress['city'];
     $shippingcountry = $shippingAddress['country'];
     $shippingphone = $shippingAddress['phone'];
     $addressDb->addAddress($contactid, 'shippingAddress', $shippingname1, $shippingname2, $shippingdepartment, $shippingstreet, $shippingpostcode, $shippingcity, $shippingcountry, $shippingphone, $this->_user['clientid'], $this->_date);
     //Phone
     $phoneDb = new Contacts_Model_DbTable_Phone();
     $phones = $phoneDb->getPhone($id);
     foreach ($phones as $phone) {
         $phoneDb->addPhone($contactid, $phone['type'], $phone['phone'], $phone['ordering']);
     }
     //Email
     $emailDb = new Contacts_Model_DbTable_Email();
     $emails = $emailDb->getEmail($id);
     foreach ($emails as $email) {
         $emailDb->addEmail($contactid, $email['email'], $email['ordering']);
     }
     //Internet
     $internetDb = new Contacts_Model_DbTable_Internet();
     $internets = $internetDb->getInternet($id);
     foreach ($internets as $internet) {
         $internetDb->addInternet($contactid, $internet['internet'], $internet['ordering']);
     }
     //Create contact folder if does not already exists
     if (!file_exists(BASE_PATH . '/files/contacts/' . $contactid . '/')) {
         mkdir(BASE_PATH . '/files/contacts/' . $contactid . '/');
         chmod(BASE_PATH . '/files/contacts/' . $contactid . '/', 0777);
     }
     $this->_flashMessenger->addMessage('MESSAGES_SUCCESFULLY_COPIED');
 }