Ejemplo n.º 1
0
 /** Change your staff profile image
  */
 public function imageAction()
 {
     $people = $this->_contacts->fetchRow($this->_contacts->select()->where('dbaseID = ' . $this->getIdentityForForms()));
     if (is_null($people)) {
         throw new Pas_Exception('Admin has not yet set up a profile for you');
     }
     $this->view->contacts = $people->toArray();
     $currentimage = $people->image;
     $form = new AddStaffPhotoForm();
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->addValidator('NotExists', true, array('./assets/staffphotos/'));
             if ($upload->isValid()) {
                 $filename = $form->getValue('image');
                 $largepath = self::PROFILEPATH;
                 $original = $largepath . $filename;
                 $name = substr($filename, 0, strrpos($filename, '.'));
                 $ext = '.jpg';
                 $converted = $name . $ext;
                 $insertData = array();
                 $insertData['image'] = $converted;
                 $insertData['updated'] = $this->getTimeForForms();
                 $insertData['updatedBy'] = $this->getIdentityForForms();
                 foreach ($insertData as $key => $value) {
                     if (is_null($value) || $value == "") {
                         unset($insertData[$key]);
                     }
                 }
                 $smallpath = self::PROFILEPATH . 'thumbnails/' . $converted;
                 $mediumpath = self::PROFILEPATH . 'resized/' . $converted;
                 //create medium size
                 $phMagick = new phMagick($original, $mediumpath);
                 $phMagick->resize(400, 0);
                 $phMagick->convert();
                 /* Zend_Debug::dump($convertsmall);
                    Zend_Debug::dump($phMagick);
                    exit; */
                 $phMagick = new phMagick($original, $smallpath);
                 $phMagick->resize(80, 0);
                 $phMagick->convert();
                 $staffs = new Contacts();
                 $where = array();
                 $where[] = $staffs->getAdapter()->quoteInto('dbaseID  = ?', $this->getIdentityForForms());
                 $staffs->update($insertData, $where);
                 $upload->receive();
                 unlink(self::PROFILEPATH . 'thumbnails/' . $currentimage);
                 unlink(self::PROFILEPATH . $currentimage);
                 unlink(self::PROFILEPATH . 'resized/' . $currentimage);
                 $this->getFlash()->addMessage('The image has been resized and added to your profile.');
                 $this->redirect('/users/account/');
             } else {
                 $this->getFlash()->addMessage('There is a problem with your upload. Probably that image exists.');
                 $this->view->errors = $upload->getMessages();
             }
         } else {
             $form->populate($formData);
             $this->getFlash()->addMessage('Check your form for errors');
         }
     }
 }
Ejemplo n.º 2
0
 private function onEdit()
 {
     if ($this->_accessLevel < ACCESS_LEVEL_EDIT) {
         CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
     }
     /* Bail out if we don't have a valid contact ID. */
     if (!$this->isRequiredIDValid('contactID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     /* Bail out if we don't have a valid company ID. */
     if (!$this->isRequiredIDValid('companyID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid company ID.');
     }
     /* Bail out if we don't have a valid owner user ID. */
     if (!$this->isOptionalIDValid('owner', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid owner user ID.');
     }
     $contactID = $_POST['contactID'];
     $companyID = $_POST['companyID'];
     $owner = $_POST['owner'];
     $formattedPhoneWork = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneWork', $_POST));
     if (!empty($formattedPhoneWork)) {
         $phoneWork = $formattedPhoneWork;
     } else {
         $phoneWork = $this->getTrimmedInput('phoneWork', $_POST);
     }
     $formattedPhoneCell = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneCell', $_POST));
     if (!empty($formattedPhoneCell)) {
         $phoneCell = $formattedPhoneCell;
     } else {
         $phoneCell = $this->getTrimmedInput('phoneCell', $_POST);
     }
     $formattedPhoneOther = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneOther', $_POST));
     if (!empty($formattedPhoneOther)) {
         $phoneOther = $formattedPhoneOther;
     } else {
         $phoneOther = $this->getTrimmedInput('phoneOther', $_POST);
     }
     $contacts = new Contacts($this->_siteID);
     if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) {
         $contactDetails = $contacts->get($contactID);
         $users = new Users($this->_siteID);
         $ownerDetails = $users->get($owner);
         if (!empty($ownerDetails)) {
             $emailAddress = $ownerDetails['email'];
             /* Get the change status email template. */
             $emailTemplates = new EmailTemplates($this->_siteID);
             $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNCONTACT');
             if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) {
                 $statusChangeTemplate = '';
             } else {
                 $statusChangeTemplate = $statusChangeTemplateRS['textReplaced'];
             }
             /* Replace e-mail template variables. */
             $stringsToFind = array('%CONTOWNER%', '%CONTFIRSTNAME%', '%CONTFULLNAME%', '%CONTCLIENTNAME%', '%CONTCATSURL%');
             $replacementStrings = array($ownerDetails['fullName'], $contactDetails['firstName'], $contactDetails['firstName'] . ' ' . $contactDetails['lastName'], $contactDetails['companyName'], '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&amp;a=show&amp;contactID=' . $contactID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&amp;a=show&amp;contactID=' . $contactID . '</a>');
             $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate);
             $email = $statusChangeTemplate;
         } else {
             $email = '';
             $emailAddress = '';
         }
     } else {
         $email = '';
         $emailAddress = '';
     }
     $firstName = $this->getTrimmedInput('firstName', $_POST);
     $lastName = $this->getTrimmedInput('lastName', $_POST);
     $title = $this->getTrimmedInput('title', $_POST);
     $department = $this->getTrimmedInput('department', $_POST);
     $reportsTo = $this->getTrimmedInput('reportsTo', $_POST);
     $email1 = $this->getTrimmedInput('email1', $_POST);
     $email2 = $this->getTrimmedInput('email2', $_POST);
     $address = $this->getTrimmedInput('address', $_POST);
     $city = $this->getTrimmedInput('city', $_POST);
     $state = $this->getTrimmedInput('state', $_POST);
     $zip = $this->getTrimmedInput('zip', $_POST);
     $notes = $this->getTrimmedInput('notes', $_POST);
     $isHot = $this->isChecked('isHot', $_POST);
     $leftCompany = $this->isChecked('leftCompany', $_POST);
     /* Departments list editor. */
     $departmentsCSV = $this->getTrimmedInput('departmentsCSV', $_POST);
     /* Bail out if any of the required fields are empty. */
     if (empty($firstName) || empty($lastName) || empty($title)) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.');
     }
     if (!eval(Hooks::get('CONTACTS_ON_EDIT_PRE'))) {
         return;
     }
     /* Update departments. */
     $companies = new Companies($this->_siteID);
     $departments = $companies->getDepartments($companyID);
     $departmentsDifferences = ListEditor::getDifferencesFromList($departments, 'name', 'departmentID', $departmentsCSV);
     $companies->updateDepartments($companyID, $departmentsDifferences);
     if (!$contacts->update($contactID, $companyID, $firstName, $lastName, $title, $department, $reportsTo, $email1, $email2, $phoneWork, $phoneCell, $phoneOther, $address, $city, $state, $zip, $isHot, $leftCompany, $notes, $owner, $email, $emailAddress)) {
         CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update contact.');
     }
     /* Update extra fields. */
     $contacts->extraFields->setValuesOnEdit($contactID);
     if (!eval(Hooks::get('CONTACTS_ON_EDIT_POST'))) {
         return;
     }
     CATSUtility::transferRelativeURI('m=contacts&a=show&contactID=' . $contactID);
 }
Ejemplo n.º 3
0
    /** provide an avatar for a contact
     */
    public function avatarAction()
    {
        $form = new AddStaffPhotoForm();
        $this->view->form = $form;
        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $upload = new Zend_File_Transfer_Adapter_Http();
                $upload->addValidator('NotExists', true, array(self::STAFFPATH));
                if ($upload->isValid()) {
                    $filename = $form->getValue('image');
                    $insertData = array();
                    $insertData['image'] = $filename;
                    $insertData['updated'] = $this->getTimeForForms();
                    $insertData['updatedBy'] = $this->getIdentityForForms();
                    foreach ($insertData as $key => $value) {
                        if (is_null($value) || $value == "") {
                            unset($insertData[$key]);
                        }
                    }
                    $original = self::STAFFPATH . $filename;
                    $name = substr($filename, 0, strrpos($filename, '.'));
                    $ext = '.jpg';
                    $converted = $name . $ext;
                    $smallpath = self::STAFFPATH . 'thumbnails/' . $converted;
                    $mediumpath = self::STAFFPATH . 'resized/' . $converted;
                    //create medium size
                    $phMagick = new phMagick($original, $mediumpath);
                    $phMagick->resize(300, 0);
                    $phMagick->convert();
                    /* Zend_Debug::dump($convertsmall);
                    	Zend_Debug::dump($phMagick);
                    	exit; */
                    $phMagick = new phMagick($original, $smallpath);
                    $phMagick->resize(100, 0);
                    $phMagick->convert();
                    $staffs = new Contacts();
                    $where = array();
                    $where[] = $staffs->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
                    $staffs->update($insertData, $where);
                    $upload->receive();
                    $this->_flashMessenger->addMessage('The image has been resized and zoomified!');
                    $this->_redirect('/admin/contacts/contact/id/' . $this->_getParam('id'));
                } else {
                    $this->_flashMessenger->addMessage('There is a problem with your upload. 
	Probably that image exists.');
                    $this->view->errors = $upload->getMessages();
                }
            } else {
                $form->populate($formData);
                $this->_flashMessenger->addMessage('Check your form for errors dude');
            }
        }
    }
Ejemplo n.º 4
0
 public function deleteprofileimageAction()
 {
     $staff = new Contacts();
     $staffs = $staff->getImage($this->_getParam('id'));
     foreach ($staffs as $staff) {
         $filename = $staff['image'];
     }
     $updateData = array();
     $updateData['image'] = NULL;
     $updateData['updated'] = $this->getTimeForForms();
     $updateData['updatedBy'] = $this->getIdentityForForms();
     $stafflist = new Contacts();
     $where = $stafflist->getAdapter()->quoteInto('id = ?', (int) $this->_getParam('id'));
     $stafflist->update($updateData, $where);
     $name = substr($filename, 0, strrpos($filename, '.'));
     $ext = '.jpg';
     $converted = $name . $ext;
     unlink('./images/staffphotos/' . $filename);
     unlink('./images/staffphotos/resized/' . $converted);
     unlink('./images/staffphotos/thumbnails/' . $converted);
 }
Ejemplo n.º 5
0
 /**
  * Generates an account from the contact's company field, if that field has a value 
  */
 private static function generateAccount(Contacts $contact)
 {
     if (isset($contact->company)) {
         $account = new Accounts();
         $account->name = $contact->company;
         if ($account->save()) {
             $account->refresh();
             $contact->company = $account->nameId;
             $contact->update();
         }
     }
 }