function console_create_user($args) { $fname = array_shift($args); $lname = array_shift($args); $email = array_shift($args); $admin = array_shift($args) == 'true'; if (is_null($fname) || is_null($lname) || is_null($email)) { throw new Exception('create_user: Missing arguments. Expected: (fname, lname, email, admin)'); } $display_name = $fname . " " . $lname; $username = str_replace(" ", "_", strtolower($display_name)); $user_data = array('username' => $username, 'display_name' => $display_name, 'email' => $email, 'password_generator' => 'random', 'timezone' => 0, 'autodetect_time_zone' => 1, 'create_contact' => false, 'company_id' => owner_company()->getId(), 'send_email_notification' => true, 'personal_project' => 0); // array try { DB::beginWork(); $user = create_user($user_data, $admin, ''); if (!$user->getContact() instanceof Contact) { $contact = new Contact(); $contact->setFirstName($fname); $contact->setLastName($lname); $contact->setEmail($email); $contact->setUserId($user->getId()); $contact->save(); } DB::commit(); } catch (Exception $e) { DB::rollback(); throw $e; } }
function testAddContact () { /* Creation du contact */ $contact = new Contact(); $contact->setEmail("*****@*****.**"); $contact->setFirstName("erwantest"); $contact->setLastName('dagorntest'); $ret = $this->sales->add($contact); echo '<pre> testAddContact <br>/'; print_r($contact); echo '<br/> retour :'.$ret; $this->assertIdentical($ret, true); $this->assertIdentical(($contact->getId() != ""), true); /* Modification du contact */ $contact->setFirstName("erwantestModif"); $ret = $this->sales->update($contact); $this->assertIdentical($ret, true); /* Suppression du contact */ $ret = $this->sales->delete($contact->getId()); $this->assertIdentical($ret, true); }
/** * @author Ignacio Vazquez <elpepe.uy at gmail dot com> * Handle quick add submit */ function quick_add() { if (array_var($_GET, 'current') == 'overview-panel') { ajx_current("reload"); }else { ajx_current("empty"); } //---------- REQUEST PARAMS -------------- // $_POST = Array ( // [member] => Array ( // [name] => pepe 333 // [dimension_id] => 1 // [parent_member_id] => 0 // [dimension_id] => 19 // ) // [contact] => Array ( // [email] => slkdjflksjdflksdf@kldsjflkdf.com // [user] => Array ( // [create-user]=>on // [type] => 25 // [first_name] => // [surname] => // ) //---------------------------------------- // Init variables $max_users = config_option('max_users'); if ($max_users && (Contacts::count() >= $max_users)) { flash_error(lang('maximum number of users reached error')); ajx_current("empty"); return; } if (!can_manage_security(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $email = trim(array_var(array_var($_POST, 'contact'),'email')) ; $member = array_var($_POST, 'member'); $name = array_var($member, 'name'); $firstName = trim(array_var(array_var($_POST, 'contact'),'first_name')); $surname = trim(array_var(array_var($_POST, 'contact'),'surname')); $parentMemberId = array_var($member, 'parent_member_id'); $objectType = ObjectTypes::findById(array_var($member, 'object_type_id'))->getName(); // 'person', 'company' $dimensionId = array_var($member, 'dimension_id'); $company = array_var(array_var(array_var($_POST, 'contact'),'user'),'company_id'); // Create new instance of Contact and set the basic fields $contact = new Contact(); $contact->setObjectName($name); if ($firstName) { $contact->setFirstName($firstName); }else{ $contact->setFirstName($name); } if ($surname) { $contact->setSurname($surname); } $contact->setCompanyId($company); $contact->setIsCompany($objectType == "company"); if ($parentMemberId){ if ( $companyId = Members::findById($parentMemberId)->getObjectId()) { $contact->setCompanyId($companyId); } } // Save Contact try { DB::beginWork(); $contact->save(); if ($email && is_valid_email($email)) { if (!Contacts::validateUniqueEmail($email)) { DB::rollback(); flash_error(lang("email address must be unique")); return false; }else{ if (!array_var (array_var(array_var($_POST, 'contact'),'user'), 'create-user')) { $contact->addEmail($email, 'personal', true); } flash_success(lang("success add contact", $contact->getObjectName())); } } // User settings $user = array_var(array_var($_POST, 'contact'),'user'); $user['username'] = str_replace(" ","",strtolower($name)) ; $this->createUserFromContactForm($user, $contact->getId(), $email); // Reload contact again due to 'createUserFromContactForm' changes Hook::fire("after_contact_quick_add", Contacts::instance()->findById($contact->getId()), $ret); DB::commit(); }catch (Exception $e){ DB::rollback(); flash_error($e->getMessage()); } // Reload evt_add("reload dimension tree", array('dim_id' => $dimensionId)); }
private function createContact() { $contact = new Contact(); $contact->setEmail($this->getFieldValue('Email')); $contact->setLastName($this->getFieldValue('LastName')); $contact->setFirstName($this->getFieldValue('FirstName')); $contact->setPhone($this->getFieldValue('Telephone')); $contact->setSujet($this->getFieldValue('Objet')); $contact->setWhatId($this->getFieldValue('whatId')); if ($this->getFieldValue('formname') == 'contact_default') { $contact->setSujet("Contactez nke : " . $contact->getSujet()); } $corp = "[Origine : " . $this->getCurrentURL() . "]\n" . $this->getFieldValue('Message'); if ($this->getFieldValue('formname') == 'contact_revendeur') { $corp .= "Ville de Résidence : " . $this->getFieldValue('Ville') . "\n" . "Port d'attache : " . $this->getFieldValue('Port') . "\n"; //"Chantier naval : ".$this->getFieldValue('ChantierNaval')."\n"; } $contact->setTexte($corp); return $contact; }
/** * Finish the installation - create owner company and administrator * * @param void * @return null */ function complete_installation() { if (Contacts::getOwnerCompany() instanceof Contact) { die('Owner company already exists'); // Somebody is trying to access this method even if the user already exists } // if $form_data = array_var($_POST, 'form'); tpl_assign('form_data', $form_data); if (array_var($form_data, 'submited') == 'submited') { try { $admin_password = trim(array_var($form_data, 'admin_password')); $admin_password_a = trim(array_var($form_data, 'admin_password_a')); if (trim($admin_password) == '') { throw new Error(lang('password value required')); } // if if ($admin_password != $admin_password_a) { throw new Error(lang('passwords dont match')); } // if DB::beginWork(); Contacts::delete(); // clear users table // Create a company $company = new Contact(); $company->setFirstName(array_var($form_data, 'company_name')); $company->setObjectName(); $company->setIsCompany(true); $company->save(); // Init default colors set_config_option('brand_colors_head_back', "424242"); set_config_option('brand_colors_tabs_back', "e7e7e7"); set_config_option('brand_colors_head_font', "FFFFFF"); set_config_option('brand_colors_tabs_font', "333333"); // Create the administrator user $administrator = new Contact(); $pergroup = PermissionGroups::findOne(array('conditions' => "`name`='Super Administrator'")); $administrator->setUserType($pergroup->getId()); $administrator->setCompanyId($company->getId()); $administrator->setUsername(array_var($form_data, 'admin_username')); $administrator->setPassword($admin_password); $administrator->setFirstname(array_var($form_data, 'admin_username')); $administrator->setObjectName(); $administrator->save(); $user_password = new ContactPassword(); $user_password->setContactId($administrator->getId()); $user_password->password_temp = $admin_password; $user_password->setPasswordDate(DateTimeValueLib::now()); $user_password->setPassword(cp_encrypt($admin_password, $user_password->getPasswordDate()->getTimestamp())); $user_password->save(); //Add email after save because is needed. $administrator->addEmail(array_var($form_data, 'admin_email'), 'personal', true); //permissions $permission_group = new PermissionGroup(); $permission_group->setName('Account Owner'); $permission_group->setContactId($administrator->getId()); $permission_group->setIsContext(false); $permission_group->setType("permission_groups"); $permission_group->save(); $administrator->setPermissionGroupId($permission_group->getId()); $administrator->save(); $company->setCreatedById($administrator->getId()); $company->setUpdatedById($administrator->getId()); $company->save(); $contact_pg = new ContactPermissionGroup(); $contact_pg->setContactId($administrator->getId()); $contact_pg->setPermissionGroupId($permission_group->getId()); $contact_pg->save(); // tab panel permissions $panels = TabPanels::getEnabled(); foreach ($panels as $panel) { $tpp = new TabPanelPermission(); $tpp->setPermissionGroupId($administrator->getPermissionGroupId()); $tpp->setTabPanelId($panel->getId()); $tpp->save(); } // dimension permissions $dimensions = Dimensions::findAll(); foreach ($dimensions as $dimension) { if ($dimension->getDefinesPermissions()) { $cdp = ContactDimensionPermissions::findOne(array("conditions" => "`permission_group_id` = " . $administrator->getPermissionGroupId() . " AND `dimension_id` = " . $dimension->getId())); if (!$cdp instanceof ContactDimensionPermission) { $cdp = new ContactDimensionPermission(); $cdp->setPermissionGroupId($administrator->getPermissionGroupId()); $cdp->setContactDimensionId($dimension->getId()); } $cdp->setPermissionType('allow all'); $cdp->save(); // contact member permisssion entries $members = $dimension->getAllMembers(); foreach ($members as $member) { $ots = DimensionObjectTypeContents::getContentObjectTypeIds($dimension->getId(), $member->getObjectTypeId()); $ots[] = $member->getObjectId(); foreach ($ots as $ot) { $cmp = ContactMemberPermissions::findOne(); if (!$cmp instanceof ContactMemberPermission) { $cmp = new ContactMemberPermission(array("conditions" => "`permission_group_id` = " . $administrator->getPermissionGroupId() . " AND `member_id` = " . $member->getId() . " AND `object_type_id` = {$ot}")); $cmp->setPermissionGroupId($administrator->getPermissionGroupId()); $cmp->setMemberId($member->getId()); $cmp->setObjectTypeId($ot); } $cmp->setCanWrite(1); $cmp->setCanDelete(1); $cmp->save(); } } } } // system permissions $sp = new SystemPermission(); $sp->setPermissionGroupId($administrator->getPermissionGroupId()); $sp->setAllPermissions(true); $sp->save(); // root permissions DB::executeAll("\r\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "contact_member_permissions (permission_group_id, member_id, object_type_id, can_delete, can_write)\r\n\t\t\t\t SELECT " . $administrator->getPermissionGroupId() . ", 0, rtp.object_type_id, rtp.can_delete, rtp.can_write FROM " . TABLE_PREFIX . "role_object_type_permissions rtp \r\n\t\t\t\t WHERE rtp.object_type_id NOT IN (SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name IN ('mail','template','file_revision')) AND rtp.role_id in (\r\n\t\t\t\t SELECT pg.id FROM " . TABLE_PREFIX . "permission_groups pg WHERE pg.type='roles' AND pg.name IN ('Super Administrator','Administrator','Manager','Executive')\r\n\t\t\t\t )\r\n\t\t\t\tON DUPLICATE KEY UPDATE member_id=0;"); Hook::fire('after_user_add', $administrator, $null); DB::commit(); $this->redirectTo('access', 'login'); } catch (Exception $e) { tpl_assign('error', $e); DB::rollback(); } // try } // if }
/** * Add single mail * * @access public * @param void * @return null */ function add_mail() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->addHelper('textile'); $mail_accounts = MailAccounts::getMailAccountsByUser(logged_user()); if (count($mail_accounts) < 1) { flash_error(lang('no mail accounts set')); ajx_current("empty"); return; } $this->setTemplate('add_mail'); $mail_data = array_var($_POST, 'mail'); $isDraft = array_var($mail_data, 'isDraft', '') == 'true' ? true : false; $isUpload = array_var($mail_data, 'isUpload', '') == 'true' ? true : false; $autosave = array_var($mail_data, 'autosave', '') == 'true'; $id = array_var($mail_data, 'id'); $mail = MailContents::findById($id); $isNew = false; if (!$mail) { $isNew = true; $mail = new MailContent(); } tpl_assign('mail_to', urldecode(array_var($_GET, 'to'))); tpl_assign('link_to_objects', array_var($_GET, 'link_to_objects')); $def_acc = $this->getDefaultAccountId(); if ($def_acc > 0) { tpl_assign('default_account', $def_acc); } tpl_assign('mail', $mail); tpl_assign('mail_data', $mail_data); tpl_assign('mail_accounts', $mail_accounts); // Form is submited if (is_array($mail_data)) { $account = MailAccounts::findById(array_var($mail_data, 'account_id')); if (!$account instanceof MailAccount) { flash_error(lang('mail account dnx')); ajx_current("empty"); return; } $accountUser = MailAccountUsers::getByAccountAndUser($account, logged_user()); if (!$accountUser instanceof MailAccountUser) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } if ($account->getOutgoingTrasnportType() == 'ssl' || $account->getOutgoingTrasnportType() == 'tls') { $available_transports = stream_get_transports(); if (array_search($account->getOutgoingTrasnportType(), $available_transports) === FALSE) { flash_error('The server does not support SSL.'); ajx_current("empty"); return; } } $cp_errs = $this->checkRequiredCustomPropsBeforeSave(array_var($_POST, 'object_custom_properties', array())); if (is_array($cp_errs) && count($cp_errs) > 0) { foreach ($cp_errs as $err) { flash_error($err); } ajx_current("empty"); return; } $subject = array_var($mail_data, 'subject'); $body = array_var($mail_data, 'body'); if (($pre_body_fname = array_var($mail_data, 'pre_body_fname')) != "") { $body = str_replace(lang('content too long not loaded'), '', $body, $count = 1); $tmp_filename = ROOT . "/tmp/{$pre_body_fname}"; if (is_file($tmp_filename)) { $body .= file_get_contents($tmp_filename); if (!$isDraft) { @unlink($tmp_filename); } } } if (array_var($mail_data, 'format') == 'html') { $css = "font-family:Arial,Verdana,sans-serif;font-size:12px;color:#222;"; Hook::fire('email_base_css', null, $css); str_replace(array("\r", "\n"), "", $css); $body = '<div style="' . $css . '">' . $body . '</div>'; $body = str_replace('<blockquote>', '<blockquote style="border-left:1px solid #987ADD;padding-left:10px;">', $body); } $type = 'text/' . array_var($mail_data, 'format'); $to = trim(array_var($mail_data, 'to')); if (str_ends_with($to, ",") || str_ends_with($to, ";")) { $to = substr($to, 0, strlen($to) - 1); } $mail_data['to'] = $to; $cc = trim(array_var($mail_data, 'cc')); if (str_ends_with($cc, ",") || str_ends_with($cc, ";")) { $cc = substr($cc, 0, strlen($cc) - 1); } $mail_data['cc'] = $cc; $bcc = trim(array_var($mail_data, 'bcc')); if (str_ends_with($bcc, ",") || str_ends_with($bcc, ";")) { $bcc = substr($bcc, 0, strlen($bcc) - 1); } $mail_data['bcc'] = $bcc; if (!$isDraft && trim($to . $cc . $bcc) == '') { flash_error(lang('recipient must be specified')); ajx_current("empty"); return; } $invalid_to = MailUtilities::validate_email_addresses($to); if (is_array($invalid_to)) { flash_error(lang('error invalid recipients', lang('mail to'), implode(", ", $invalid_to))); ajx_current("empty"); return; } $invalid_cc = MailUtilities::validate_email_addresses($cc); if (is_array($invalid_cc)) { flash_error(lang('error invalid recipients', lang('mail CC'), implode(", ", $invalid_cc))); ajx_current("empty"); return; } $invalid_bcc = MailUtilities::validate_email_addresses($bcc); if (is_array($invalid_bcc)) { flash_error(lang('error invalid recipients', lang('mail BCC'), implode(", ", $invalid_bcc))); ajx_current("empty"); return; } $last_mail_in_conversation = array_var($mail_data, 'last_mail_in_conversation'); $conversation_id = array_var($mail_data, 'conversation_id'); if ($last_mail_in_conversation && $conversation_id) { $new_mail_in_conversation = MailContents::getLastMailIdInConversation($conversation_id, true); if ($new_mail_in_conversation != $last_mail_in_conversation) { ajx_current("empty"); evt_add("new email in conversation", array('id' => $new_mail_in_conversation, 'genid' => array_var($_POST, 'instanceName'))); return; } } $mail->setFromAttributes($mail_data); $mail->setTo($to); $mail->setCc($cc); $mail->setBcc($bcc); $mail->setSubject($mail_data['subject']); $utils = new MailUtilities(); // attachment $linked_attachments = array(); $attachments = array(); $objects = array_var($_POST, 'linked_objects'); $attach_contents = array_var($_POST, 'attach_contents', array()); if (is_array($objects)) { $err = 0; $count = -1; foreach ($objects as $objid) { $count++; $split = explode(":", $objid); if (count($split) == 2) { $object = get_object_by_manager_and_id($split[1], $split[0]); } else { if (count($split) == 4) { if ($split[0] == 'FwdMailAttach') { $tmp_filename = ROOT . "/tmp/" . logged_user()->getId() . "_" . $mail_data['account_id'] . "_FwdMailAttach_" . $split[3]; if (is_file($tmp_filename)) { $attachments[] = array("data" => file_get_contents($tmp_filename), "name" => $split[1], "type" => $split[2]); continue; } } } } if (!isset($object) || !$object) { flash_error(lang('file dnx')); $err++; } else { if (isset($attach_contents[$count])) { if ($split[0] == 'ProjectFiles') { $file = ProjectFiles::findById($object->getId()); if (!$file instanceof ProjectFile) { flash_error(lang('file dnx')); $err++; } // if if (!$file->canDownload(logged_user())) { flash_error(lang('no access permissions')); $err++; } // if $attachments[] = array("data" => $file->getFileContent(), "name" => $file->getFilename(), "type" => $file->getTypeString()); } else { if ($split[0] == 'MailContents') { $email = MailContents::findById($object->getId()); if (!$email instanceof MailContent) { flash_error(lang('email dnx')); $err++; } // if if (!$email->canView(logged_user())) { flash_error(lang('no access permissions')); $err++; } // if $attachments[] = array("data" => $email->getContent(), "name" => $email->getSubject() . ".eml", "type" => 'message/rfc822'); } } } else { $linked_attachments[] = array("data" => $object->getViewUrl(), "name" => clean($object->getObjectName()), "type" => lang($object->getObjectTypeName()), "manager" => $object->getObjectManagerName(), "id" => $object->getId()); } } } if ($err > 0) { flash_error(lang('some objects could not be linked', $err)); ajx_current('empty'); return; } } $to = preg_split('/;|,/', $to); $to = $utils->parse_to($to); if ($body == '') { $body .= ' '; } try { if (count($linked_attachments)) { $linked_users = array(); foreach ($to as $to_user) { $linked_user = Users::getByEmail($to_user[1]); if (!$linked_user instanceof User) { try { $linked_user = create_user_from_email($to_user[1], $to_user[0]); } catch (Exception $e) { //Logger::log($e->getMessage()); } } if ($linked_user instanceof User) { $linked_users[] = $linked_user; } } $linked_atts = $type == 'text/html' ? '<div style="font-family:arial;"><br><br><br><span style="font-size:12pt;font-weight:bold;color:#777">' . lang('linked attachments') . '</span><ul>' : "\n\n\n-----------------------------------------\n" . lang('linked attachments') . "\n\n"; foreach ($linked_attachments as $att) { $linked_atts .= $type == 'text/html' ? '<li><a href="' . $att['data'] . '">' . $att['name'] . ' (' . $att['type'] . ')</a></li>' : $att['name'] . ' (' . $att['type'] . '): ' . $att['data'] . "\n"; foreach ($linked_users as $linked_user) { try { $linked_user->giveAccessToObject(get_object_by_manager_and_id($att['id'], $att['manager'])); } catch (Exception $e) { //Logger::log($e->getMessage()); } } } $linked_atts .= $type == 'text/html' ? '</ul></div>' : ''; } else { $linked_atts = ''; } $body .= $linked_atts; if (count($attachments) > 0) { $i = 0; $str = ""; /* foreach ($attachments as $att) { $str .= "--000000000000000000000000000$i\n"; $str .= "Name: ".$att['name'] .";\n"; $str .= "Type: ".$att['type'] .";\n"; //$str .= "Encoding: ".$att['type'] .";\n"; $str .= base64_encode($att['data']) ."\n"; $str .= "--000000000000000000000000000$i--\n"; $i++; } */ $str = "#att_ver 2\n"; foreach ($attachments as $att) { $rep_id = $utils->saveContent($att['data']); $str .= $att['name'] . "," . $att['type'] . "," . $rep_id . "\n"; } // save attachments, when mail is sent this file is deleted and full content is saved $repository_id = $utils->saveContent($str); if (!$isNew) { if (FileRepository::isInRepository($mail->getContentFileId())) { // delete old attachments $content = FileRepository::getFileContent($mail->getContentFileId()); if (str_starts_with($content, "#att_ver")) { $lines = explode("\n", $content); foreach ($lines as $line) { if (!str_starts_with($line, "#") && trim($line) !== "") { $data = explode(",", $line); if (isset($data[2]) && FileRepository::isInRepository($data[2])) { FileRepository::deleteFile($data[2]); } } } } FileRepository::deleteFile($mail->getContentFileId()); } } $mail->setContentFileId($repository_id); } $mail->setHasAttachments(is_array($attachments) && count($attachments) > 0 ? 1 : 0); $mail->setAccountEmail($account->getEmailAddress()); $mail->setSentDate(DateTimeValueLib::now()); $mail->setReceivedDate(DateTimeValueLib::now()); DB::beginWork(); $msg_id = MailUtilities::generateMessageId($account->getEmailAddress()); $conversation_id = array_var($mail_data, 'conversation_id'); $in_reply_to_id = array_var($mail_data, 'in_reply_to_id'); if ($conversation_id) { $in_reply_to = MailContents::findById(array_var($mail_data, 'original_id')); if ($in_reply_to instanceof MailContent && $in_reply_to->getSubject() && strpos(strtolower($mail->getSubject()), strtolower($in_reply_to->getSubject())) === false) { $conversation_id = null; $in_reply_to_id = ''; } } if (!$conversation_id) { $conversation_id = MailContents::getNextConversationId($account->getId()); } $mail->setMessageId($msg_id); $mail->setConversationId($conversation_id); $mail->setInReplyToId($in_reply_to_id); $mail->setUid(gen_id()); $mail->setState($isDraft ? 2 : 200); $mail->setIsPrivate(false); set_user_config_option('last_mail_format', array_var($mail_data, 'format', 'plain'), logged_user()->getId()); $body = utf8_safe($body); if (array_var($mail_data, 'format') == 'html') { $mail->setBodyHtml($body); $mail->setBodyPlain(utf8_safe(html_to_text($body))); } else { $mail->setBodyPlain($body); $mail->setBodyHtml(''); } $mail->setFrom($account->getEmailAddress()); $mail->setFromName(logged_user()->getDisplayName()); $mail->save(); $mail->setIsRead(logged_user()->getId(), true); $mail->setTagsFromCSV(array_var($mail_data, 'tags')); // autoclassify sent email // if replying a classified email classify on same workspace $classified = false; if (array_var($mail_data, 'original_id')) { $in_reply_to = MailContents::findById(array_var($mail_data, 'original_id')); if ($in_reply_to instanceof MailContent) { $workspaces = $in_reply_to->getWorkspaces(); foreach ($workspaces as $w) { if ($mail->canAdd(logged_user(), $w)) { $mail->addToWorkspace($w); $classified = true; } } } } if (!$classified && $account->getWorkspace() instanceof Project) { $mail->addToWorkspace($account->getWorkspace()); } if (!$classified && active_project() instanceof Project) { $mail->addToWorkspace(active_project()); } $object_controller = new ObjectController(); $object_controller->add_custom_properties($mail); $object_controller->link_to_new_object($mail); if (array_var($mail_data, 'link_to_objects') != '') { $lto = explode('|', array_var($mail_data, 'link_to_objects')); foreach ($lto as $object_string) { $split_object = explode('-', $object_string); $object = get_object_by_manager_and_id($split_object[1], $split_object[0]); if ($object instanceof ProjectDataObject) { $mail->linkObject($object); } } } ApplicationLogs::createLog($mail, $mail->getWorkspaces(), ApplicationLogs::ACTION_ADD); if (user_config_option('create_contacts_from_email_recipients') && can_manage_contacts(logged_user())) { // automatically create contacts foreach ($to as $recipient) { $recipient_name = trim($recipient[0]); $recipient_address = trim($recipient[1]); if (!$recipient_address) { continue; } $contact = Contacts::getByEmail($recipient_address); if (!$contact instanceof Contact) { try { $contact = new Contact(); $contact->setEmail($recipient_address); if ($recipient_name && $recipient_name != $recipient_address) { $contact->setFirstName($recipient_name); } else { $index = strpos($recipient_address, "@"); $recipient_name = substr($recipient_address, 0, $index); $contact->setFirstName($recipient_name); } $contact->save(); } catch (Exception $e) { // TODO: show error message? } } } } DB::commit(); if (!$autosave) { if ($isDraft) { flash_success(lang('success save mail')); ajx_current("empty"); } else { evt_add("must send mails", array("account" => $mail->getAccountId())); //flash_success(lang('mail is being sent')); ajx_current("back"); } evt_add("email saved", array("id" => $mail->getId(), "instance" => array_var($_POST, 'instanceName'))); } else { evt_add("draft mail autosaved", array("id" => $mail->getId(), "hf_id" => $mail_data['hf_id'])); flash_success(lang('success autosave draft')); ajx_current("empty"); } } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } // try } // if }
public function parseContact($data) { $contact = new Contact(); if (isset($data['id'])) { $contact->setId($data['id']); } if (isset($data['firstName'])) { $contact->setFirstName($data['firstName']); } if (isset($data['name'])) { $contact->setName($data['name']); } if (isset($data['mail'])) { $contact->setMail($data['mail']); } if (isset($data['company'])) { $contact->setCompany($data['company']); } if (isset($data['phone'])) { $contact->setPhone($data['phone']); } if (isset($data['phone2'])) { $contact->setPhone2($data['phone2']); } if (isset($data['phone3'])) { $contact->setPhone3($data['phone3']); } if (isset($data['address'])) { $contact->setAddress($this->addressService->getAddress($data['address'])); } if (isset($data['type'])) { $contact->setType($this->typeService->getType($data['type'])); } if (isset($data['exchangeId'])) { $contact->setExchangeId($data['exchangeId']); } return $contact; }
/** * Finish the installation - create owner company and administrator * * @param void * @return null */ function complete_installation() { if(Contacts::getOwnerCompany() instanceof Contact) { die('Owner company already exists'); // Somebody is trying to access this method even if the user already exists } // if $form_data = array_var($_POST, 'form'); tpl_assign('form_data', $form_data); if(array_var($form_data, 'submited') == 'submited') { try { $admin_password = trim(array_var($form_data, 'admin_password')); $admin_password_a = trim(array_var($form_data, 'admin_password_a')); if(trim($admin_password) == '') { throw new Error(lang('password value required')); } // if if($admin_password <> $admin_password_a) { throw new Error(lang('passwords dont match')); } // if DB::beginWork(); Contacts::delete(); // clear users table // Create a company $company = new Contact(); $company->setFirstName(array_var($form_data, 'company_name')); $company->setObjectName(); $company->setIsCompany(true); $company->save(); // Init default colors set_config_option('brand_colors_head_back', "000000"); set_config_option('brand_colors_tabs_back', "14780e"); set_config_option('brand_colors_head_font', "ffffff"); set_config_option('brand_colors_tabs_font', "ffffff"); // Create the administrator user $administrator = new Contact(); $pergroup = PermissionGroups::findOne(array('conditions'=>"`name`='Super Administrator'")); $administrator->setUserType($pergroup->getId()); $administrator->setCompanyId($company->getId()); $administrator->setUsername(array_var($form_data, 'admin_username')); $administrator->setPassword($admin_password); $administrator->setFirstname(array_var($form_data, 'admin_username')); $administrator->setObjectName(); $administrator->save(); $user_password = new ContactPassword(); $user_password->setContactId($administrator->getId()); $user_password->password_temp = $admin_password; $user_password->setPasswordDate(DateTimeValueLib::now()); $user_password->setPassword(cp_encrypt($admin_password, $user_password->getPasswordDate()->getTimestamp())); $user_password->save(); //Add email after save because is needed. $administrator->addEmail(array_var($form_data, 'admin_email'), 'personal', true); //permissions $permission_group = new PermissionGroup(); $permission_group->setName('Account Owner'); $permission_group->setContactId($administrator->getId()); $permission_group->setIsContext(false); $permission_group->setType("permission_groups"); $permission_group->save(); $administrator->setPermissionGroupId($permission_group->getId()); $administrator->save(); $company->setCreatedById($administrator->getId()); $company->setUpdatedById($administrator->getId()); $company->save(); $contact_pg = new ContactPermissionGroup(); $contact_pg->setContactId($administrator->getId()); $contact_pg->setPermissionGroupId($permission_group->getId()); $contact_pg->save(); // tab panel permissions $panels = TabPanels::getEnabled(); foreach ($panels as $panel) { $tpp = new TabPanelPermission(); $tpp->setPermissionGroupId($administrator->getPermissionGroupId()); $tpp->setTabPanelId($panel->getId()); $tpp->save(); } // dimension permissions $dimensions = Dimensions::findAll(); foreach ($dimensions as $dimension) { if ($dimension->getDefinesPermissions()) { $cdp = ContactDimensionPermissions::findOne(array("conditions" => "`permission_group_id` = ".$administrator->getPermissionGroupId()." AND `dimension_id` = ".$dimension->getId())); if (!$cdp instanceof ContactDimensionPermission) { $cdp = new ContactDimensionPermission(); $cdp->setPermissionGroupId($administrator->getPermissionGroupId()); $cdp->setContactDimensionId($dimension->getId()); } $cdp->setPermissionType('allow all'); $cdp->save(); // contact member permisssion entries $members = $dimension->getAllMembers(); foreach ($members as $member) { $ots = DimensionObjectTypeContents::getContentObjectTypeIds($dimension->getId(), $member->getObjectTypeId()); $ots[]=$member->getObjectId(); foreach ($ots as $ot) { $cmp = ContactMemberPermissions::findOne(); if (!$cmp instanceof ContactMemberPermission) { $cmp = new ContactMemberPermission(array("conditions" => "`permission_group_id` = ".$administrator->getPermissionGroupId()." AND `member_id` = ".$member->getId()." AND `object_type_id` = $ot")); $cmp->setPermissionGroupId($administrator->getPermissionGroupId()); $cmp->setMemberId($member->getId()); $cmp->setObjectTypeId($ot); } $cmp->setCanWrite(1); $cmp->setCanDelete(1); $cmp->save(); } } } } // system permissions $sp = new SystemPermission(); $sp->setPermissionGroupId($administrator->getPermissionGroupId()); $sp->setAllPermissions(true); $sp->save(); Hook::fire('after_user_add', $administrator, $null); DB::commit(); $this->redirectTo('access', 'login'); } catch(Exception $e) { tpl_assign('error', $e); DB::rollback(); } // try } // if } // complete_installation
function signup_user_constant_contact($firstname, $lastname, $email, $list) { global $premise_base; require_once PREMISE_LIB_DIR . 'constant_contact_api/constant_contact_api.php'; $settings = $premise_base->get_settings(); $optin = $settings['optin']; $premise_base->setup_constant_contact($this->_optin_ConstantContactKey, $optin['constant-contact-username'], $optin['constant-contact-password']); $collection = new ContactsCollection(); list($search) = $collection->searchByEmail($email); if (!empty($search)) { foreach ($search as $possible) { if ($email == $possible->getEmailAddress()) { $contact = $collection->getContact($possible->getLink()); break; } } } $listKey = 'http://api.constantcontact.com/ws/customers/' . $optin['constant-contact-username'] . '/lists/' . $list; if ($contact) { $existingLists = $contact->getLists(); if (in_array($listKey, $existingLists)) { return array('error' => __('You have already subscribed to this mailing list', 'premise')); } else { $contact->setLists($listKey); } $contact->setFirstName($firstname); $contact->setLastName($lastname); $result = $collection->updateContact($contact->getId(), $contact); } else { $contact = new Contact(); $contact->setFirstName($firstname); $contact->setLastName($lastname); $contact->setEmailAddress($email); $contact->setLists($listKey); $result = $collection->createContact($contact); } $first = substr((string) $result, 0, 1); if ($first != 2) { return array('error' => __('Could not subscribe you to this mailing list', 'premise')); } return true; }
function contactParser($data) { $contact = new Contact(); if (isset($data['id'])) { $contact->setId($data['id']); } if (isset($data['firstName'])) { $contact->setFirstName($data['firstName']); } if (isset($data['name'])) { $contact->setName($data['name']); } if (isset($data['mail'])) { $contact->setMail($data['mail']); } if (isset($data['phone'])) { $contact->setPhone($data['phone']); } if (isset($data['phone2'])) { $contact->setPhone2($data['phone2']); } if (isset($data['phone3'])) { $contact->setPhone3($data['phone3']); } if (isset($data['company'])) { $contact->setCompany($data['company']); } if (isset($data['address'])) { $dataAddress = $data['address']; $address = new Address(); if (isset($dataAddress['id'])) { $address->setId($dataAddress['id']); } if (isset($dataAddress['line1'])) { $address->setLine1($dataAddress['line1']); } if (isset($dataAddress['line2'])) { $address->setLine2($dataAddress['line2']); } if (isset($dataAddress['zipCode'])) { $address->setZipCode($dataAddress['zipCode']); } if (isset($dataAddress['city'])) { $address->setCity($dataAddress['city']); } if (isset($dataAddress['latitude']) && isset($dataAddress['longitude'])) { $address->setLatitude($dataAddress['latitude']); $address->setLongitude($dataAddress['longitude']); } else { $mapService = new GoogleMapService(); $latlng = $mapService->getLatLong($address); if ($latlng != [] && sizeof($latlng) == 2) { $address->setLatitude($latlng[0]); $address->setLongitude($latlng[1]); } } $contact->setAddress($address); } if (isset($data['type'])) { if (isset($data['type']['id']) && isset($data['type']['name'])) { $type = new Type($data['type']['id'], $data['type']['name']); } elseif (isset($data['type']['name'])) { $type = new Type(null, $data['type']['name']); } else { $type = null; } $contact->setType($type); } if (isset($data['exchangeId'])) { $contact->setExchangeId($data['exchangeId']); } return $contact; }
public function parseContact($contactObject) { $contact = new Contact(); $contact->setPhoneNumber($contactObject->phone_number); $contact->setFirstName($contactObject->first_name); if (property_exists($contactObject, 'last_name')) { $contact->setLastName($contactObject->last_name); } if (property_exists($contactObject, 'user_id')) { $contact->setUserId($contactObject->user_id); } return $contact; }
/** * Used to get all the contacts from Exchange * @return array of contact */ public function getAllContacts() { try { $contactList = []; $request = new EWSType_FindItemType(); $request->ItemShape = new EWSType_ItemResponseShapeType(); $request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES; $request->ContactsView = new EWSType_ContactsViewType(); $request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType(); $request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType(); $request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CONTACTS; $request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW; $response = parent::getEws()->FindItem($request); if (isset($response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Contact)) { $stdContacts = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Contact; } else { return null; } foreach ($stdContacts as $c) { $contact = new Contact(); if (isset($c->ItemId->Id)) { $contact->setExchangeId($c->ItemId->Id); } if (isset($c->CompleteName)) { if (isset($c->CompleteName->FirstName)) { $contact->setFirstName($c->CompleteName->FirstName); } if (isset($c->CompleteName->LastName)) { if (strpos($c->CompleteName->LastName, '--') !== false) { $nameAndType = $this->getTypeFromName($c->CompleteName->LastName); if (sizeof($nameAndType) == 2) { $contact->setName($nameAndType[0]); $typeService = new TypeService(); $type = $typeService->getType($nameAndType[1]); if ($type != null) { $contact->setType($type); } else { $contact->setType(null); } } else { $contact->setName($c->CompleteName->LastName); } } else { $contact->setName($c->CompleteName->LastName); } } } if (isset($c->PhoneNumbers->Entry)) { if (is_array($c->PhoneNumbers->Entry)) { $contact->setPhone($c->PhoneNumbers->Entry[0]->_); if (sizeof($c->PhoneNumbers->Entry) > 1) { if (isset($c->PhoneNumbers->Entry[1])) { $contact->setPhone2($c->PhoneNumbers->Entry[1]->_); } } if (sizeof($c->PhoneNumbers->Entry) > 2) { if (isset($c->PhoneNumbers->Entry[2])) { $contact->setPhone3($c->PhoneNumbers->Entry[2]->_); } } } else { $contact->setPhone($c->PhoneNumbers->Entry->_); } } if (isset($c->EmailAddresses->Entry)) { if (is_array($c->EmailAddresses->Entry)) { $contact->setMail($c->EmailAddresses->Entry[0]->_); } else { $contact->setMail($c->EmailAddresses->Entry->_); } } if (isset($c->CompanyName)) { $contact->setCompany($c->CompanyName); } if (isset($c->PhysicalAddresses->Entry)) { $address = new Address(); $stdAddress = $c->PhysicalAddresses->Entry; if (is_array($stdAddress)) { $address->setLine1($stdAddress[0]->Street); $address->setZipCode($stdAddress[0]->PostalCode); $address->setCity($stdAddress[0]->City); } else { if (isset($stdAddress->Street)) { $address->setLine1($stdAddress->Street); } if (isset($stdAddress->PostalCode)) { $address->setZipCode($stdAddress->PostalCode); } if (isset($stdAddress->City)) { $address->setCity($stdAddress->City); } } $contact->setAddress($address); } array_push($contactList, $contact); } if ($contactList == []) { $contactList = null; } return $contactList; } catch (Exception $e) { error_log($e->getMessage()); } return null; }
private function submitManagerApplication() { $request = \Server::getCurrentRequest(); $vars = $request->getVars(); $username = $request->getVar('managerUsername'); $password = $request->getVar('managerPassword'); $first_name = $request->getVar('contactFirstName'); $last_name = $request->getVar('contactLastName'); $email = $request->getVar('emailAddress'); $phone = $request->getVar('phoneNumber'); $hours = $request->getVar('contactHours'); $company_name = $request->getVar('companyName'); $company_url = $request->getVar('companyUrl'); $company_address = $request->getVar('companyAddress'); $private = $request->getVar('managerType'); $contact = new Contact(); try { $contact->setUsername($username); $contact->setPassword($password); $contact->setFirstName($first_name); $contact->setLastName($last_name); $contact->setEmailAddress($email); $contact->setPhone($phone); $contact->setTimesAvailable($hours); if ($private == 'false') { $contact->setPrivate(false); if (empty($company_name)) { throw \Exception('Missing company name'); } else { $contact->setCompanyName($company_name); } if (empty($company_address)) { throw \Exception('Missing company address'); } else { $contact->setCompanyAddress($company_address); } $contact->setCompanyUrl($company_url); } else { $contact->setPrivate(true); $contact->setCompanyName('Private Renter'); } $contact->setApproved(false); $contact->save(); $this->emailApprovalNeeded(); } catch (\Exception $ex) { $address = \PHPWS_Settings::get('properties', 'email'); \Error::log($ex); $this->title = 'Sorry!'; $this->content = <<<EOF <p>Your manager submission could not be processed. Please email <a href="mailto:{$address}">{$address}</a> to inform them of your problem.</p> EOF; $this->content .= $ex->getMessage(); return; } // success $this->title = 'Thank you'; $this->content = <<<EOF <p>We will review your manager application and email your confirmation.</p> <p><a href="./">Return to the home page</a></p> EOF; }