/**
 * make domain registration api call
 * 
 * @param array $params call params with domain details
 * 
 * @return mixed array containig error message will return if error was ocurred, 'success' string in other case
 */
function stregistry_RegisterDomain($params)
{
    // init connection
    if (($status = __initConnectionAndAuthorize($params)) !== true) {
        return __errorArray($status);
    }
    $domain = new Domain($params['domainname']);
    // create domain contacts
    $contactIds = array();
    foreach (array('registrant', 'admin', 'tech', 'billing') as $contactType) {
        $contact = new Contact();
        $contact->setEmail($params['email'])->setPhoneNumber($params['phonenumberformatted'] ?: '')->setName($params['fullname'])->setOrganization($params['companyname'])->setAddress($params['address1'], $params['address1'] ?: '')->setCity($params['city'])->setState($params['fullstate'])->setPostalCode($params['postcode'])->setCountryCode($params['countrycode']);
        $json = STRegistry::Contacts()->create($contact);
        if (!ResponseHelper::isSuccess($json)) {
            return __errorArray(ResponseHelper::fromJSON($json)->message);
        }
        $contactIds[$contactType] = ResponseHelper::fromJSON($json, 'creData')->result['id'];
    }
    $domain->setContacts($contactIds['registrant'], $contactIds['admin'], $contactIds['tech'], $contactIds['billing']);
    if ($params['idprotection']) {
        $domain->setPrivacyContacts(STRegistryPrivacyContact::getRegistrantId(), STRegistryPrivacyContact::getAdminId(), STRegistryPrivacyContact::getTechId(), STRegistryPrivacyContact::getBillingId());
    }
    // add nameservers
    foreach (array('ns1', 'ns2', 'ns3', 'ns4', 'ns5') as $nsKey) {
        if (!empty($params[$nsKey])) {
            $domain->addNameServer($params[$nsKey]);
        }
    }
    // creating domain
    $json = STRegistry::Domains()->create($domain, $params['regperiod']);
    if (!ResponseHelper::isSuccess($json)) {
        return __errorArray(ResponseHelper::fromJSON($json)->message);
    }
    return 'success';
}
Ejemplo n.º 2
0
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;
    }
}
Ejemplo n.º 3
0
 private function createContact(array $data)
 {
     $contact = new Contact();
     $contact->setEmail($data['email']);
     $contact->setName($data['name']);
     $contact->setPhoto($data['photo']);
     return $contact;
 }
Ejemplo n.º 4
0
 /**
  * Recupera um contato pelo email.
  * @param string $email O email do contato que se deseja recuperar.
  */
 public function getContact($email)
 {
     $contact = $this->contactStorage->findOne($email);
     if ($contact !== null) {
         return $contact;
     }
     $contact = new Contact();
     $contact->setEmail($email);
     return $contact;
 }
Ejemplo n.º 5
0
 public function testAddContacts()
 {
     for ($i = 0; $i < MAX_CONTACTS; $i++) {
         $contact = new Contact();
         $contact->setId($i);
         $contact->setName($this->names[$i % sizeof($this->names)] . " " . $i);
         $contact->setEmail($this->names[$i % sizeof($this->names)] . $i . "@email.com");
         $contact->setPhoneContact(999999999);
         $this->agenda->addContact($contact);
     }
 }
Ejemplo n.º 6
0
	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);
		
	}
Ejemplo n.º 7
0
 /**
  * Render contact page for Kiosk application
  *
  * @param Request $request
  * @param null $contactId
  * @return array
  * @throws \Symfony\Component\Form\Exception\AlreadyBoundException
  * @Route("/check_contact/{contactId}",
  *          name="kiosk_check_contact",
  *          defaults={"contactId" = null},
  *          requirements={"contactId" = "\d+"}
  * )
  * @Template()
  */
 public function checkContactAction(Request $request, $contactId = null)
 {
     $em = $this->getDoctrine()->getManager();
     $form = $this->createEmailForm();
     $form->bind($request);
     $email = $form->get('email')->getData();
     if (!$email && is_null($contactId)) {
         $hasContact = false;
         $contact = null;
     } else {
         if (!is_null($contactId)) {
             $contact = $em->getRepository('BraemCRMBundle:Contact')->find($contactId);
         } else {
             $contact = $em->getRepository('BraemCRMBundle:Contact')->findOneBy(array('email' => $email));
         }
         $hasContact = $contact ? true : false;
     }
     if (!$hasContact) {
         $contact = new Contact();
         $contact->setEmail($email);
         $form = $this->createForm(new ContactKioskType(), $contact, array('em' => $em, 'kiosk.phone.service' => $this->get('kiosk.phone.service')));
     }
     return array('contact' => $contact, 'hasContact' => $hasContact, 'form' => $form->createView());
 }
Ejemplo n.º 8
0
 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;
 }
 /**
  *
  * @param MailingList $source
  * @param Campaign $campaign
  * @param string $name
  * @return MailingList|null
  */
 public function copy(MailingList $source, Campaign $campaign = null, $name = null)
 {
     $con = $this->getConnection();
     $con->beginTransaction();
     try {
         $target = new MailingList();
         $target->setStatus(MailingListTable::STATUS_DRAFT);
         if ($name) {
             $target->setName($name);
         } else {
             $target->setName($source->getName() . ' copy ' . gmdate('Y-M-d H:i'));
         }
         if ($campaign) {
             $target->setCampaign($campaign);
         }
         $target->save();
         $meta_ids = array();
         $choice_ids = array();
         foreach ($source->getMailingListMeta() as $meta_source) {
             /* @var $meta_source MailingListMeta */
             $meta = new MailingListMeta();
             $meta->setMailingList($target);
             $meta->setKind($meta_source->getKind());
             $meta->setName($meta_source->getName());
             $meta->setSubst($meta_source->getSubst());
             $meta->save();
             $meta_ids[$meta_source->getId()] = $meta->getId();
             foreach ($meta_source->getMailingListMetaChoice() as $choice_source) {
                 /* @var $choice_source MailingListMetaChoice */
                 $choice = new MailingListMetaChoice();
                 $choice->setMailingListMeta($meta);
                 $choice->setChoice($choice_source->getChoice());
                 $choice->save();
                 $choice_ids[$choice_source->getId()] = $choice->getId();
             }
         }
         foreach ($source->getContact() as $contact_source) {
             /* @var $contact_source Contact */
             $contact = new Contact();
             $contact->setMailingList($target);
             $contact->setStatus($contact_source->getStatus());
             $contact->setEmail($contact_source->getEmail());
             $contact->setGender($contact_source->getGender());
             $contact->setFirstname($contact_source->getFirstname());
             $contact->setLastname($contact_source->getLastname());
             $contact->setCountry($contact_source->getCountry());
             $contact->save();
             foreach ($contact_source->getContactMeta() as $contact_meta_source) {
                 /* @var $contact_meta_source ContactMeta */
                 $contact_meta = new ContactMeta();
                 $contact_meta->setContact($contact);
                 $contact_meta->setValue($contact_meta_source->getValue());
                 $contact_meta->setMailingListMetaId($meta_ids[$contact_meta_source->getMailingListMetaId()]);
                 if ($contact_meta_source->getMailingListMetaChoiceId()) {
                     $contact_meta->setMailingListMetaChoiceId($choice_ids[$contact_meta_source->getMailingListMetaChoiceId()]);
                 }
                 $contact_meta->save();
             }
         }
         $con->commit();
         return $target;
     } catch (Exception $e) {
         $con->rollback();
     }
     return null;
 }
Ejemplo n.º 10
0
 /**
  * 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
 }
 /**
  * Finish the installation - create owner company and administrator
  *
  * @param void
  * @return null
  */
 function complete_installation()
 {
     if (Companies::getOwnerCompany() instanceof Company) {
         die('Owner company already exists');
         // Somebody is trying to access this method even if the user already exists
     }
     // if
     $this->setLayout('complete_install');
     $form_data = array_var($_POST, 'form');
     tpl_assign('form_data', $form_data);
     if (array_var($form_data, 'submitted') == 'submitted') {
         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();
             Users::delete();
             // clear users table
             Companies::delete();
             // clear companies table
             // Create the administrator user
             $administrator = new User();
             $administrator->setId(1);
             $administrator->setUsername(array_var($form_data, 'admin_username'));
             $administrator->setEmail(array_var($form_data, 'admin_email'));
             $administrator->setPassword($admin_password);
             $administrator->setIsAdmin(true);
             $administrator->setAutoAssign(true);
             $administrator->save();
             // Create the contact for administrator
             $administrator_contact = new Contact();
             $administrator_contact->setId(1);
             $administrator_contact->setCompanyId(1);
             $administrator_contact->setEmail(array_var($form_data, 'admin_email'));
             $administrator_contact->setUserId($administrator->getId());
             $administrator_contact->setDisplayName($administrator->getUsername());
             $administrator_contact->save();
             // Create a company
             $company = new Company();
             $company->setId(1);
             $company->setClientOfId(0);
             $company->setName(array_var($form_data, 'company_name'));
             $company->setCreatedById(1);
             $company->save();
             DB::commit();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if
 }
Ejemplo n.º 12
0
function create_user($user_data, $permissionsString)
{
    $user = new User();
    $user->setUsername(array_var($user_data, 'username'));
    $user->setDisplayName(array_var($user_data, 'display_name'));
    $user->setEmail(array_var($user_data, 'email'));
    $user->setCompanyId(array_var($user_data, 'company_id'));
    $user->setType(array_var($user_data, 'type'));
    $user->setTimezone(array_var($user_data, 'timezone'));
    if (!logged_user() instanceof User || can_manage_security(logged_user())) {
        $user->setCanEditCompanyData(array_var($user_data, 'can_edit_company_data'));
        $user->setCanManageSecurity(array_var($user_data, 'can_manage_security'));
        $user->setCanManageWorkspaces(array_var($user_data, 'can_manage_workspaces'));
        $user->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration'));
        $user->setCanManageContacts(array_var($user_data, 'can_manage_contacts'));
        $user->setCanManageTemplates(array_var($user_data, 'can_manage_templates'));
        $user->setCanManageReports(array_var($user_data, 'can_manage_reports'));
        $user->setCanManageTime(array_var($user_data, 'can_manage_time'));
        $user->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts'));
        $other_permissions = array();
        Hook::fire('add_user_permissions', $user, $other_permissions);
        foreach ($other_permissions as $k => $v) {
            $user->setColumnValue($k, array_var($user_data, $k));
        }
    }
    if (array_var($user_data, 'password_generator', 'random') == 'random') {
        // Generate random password
        $password = UserPasswords::generateRandomPassword();
    } else {
        // Validate input
        $password = array_var($user_data, 'password');
        if (trim($password) == '') {
            throw new Error(lang('password value required'));
        }
        // if
        if ($password != array_var($user_data, 'password_a')) {
            throw new Error(lang('passwords dont match'));
        }
        // if
    }
    // if
    $user->setPassword($password);
    $user->save();
    $user_password = new UserPassword();
    $user_password->setUserId($user->getId());
    $user_password->setPasswordDate(DateTimeValueLib::now());
    $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp()));
    $user_password->password_temp = $password;
    $user_password->save();
    if (array_var($user_data, 'autodetect_time_zone', 1) == 1) {
        set_user_config_option('autodetect_time_zone', 1, $user->getId());
    }
    if ($user->getType() == 'admin') {
        if ($user->getCompanyId() != owner_company()->getId() || logged_user() instanceof User && !can_manage_security(logged_user())) {
            // external users can't be admins or logged user has no rights to create admins => set as Normal
            $user->setType('normal');
        } else {
            $user->setAsAdministrator(true);
        }
    }
    /* create contact for this user*/
    if (array_var($user_data, 'create_contact', 1)) {
        // if contact with same email exists take it, else create new
        $contact = Contacts::getByEmail($user->getEmail(), true);
        if (!$contact instanceof Contact) {
            $contact = new Contact();
            $contact->setEmail($user->getEmail());
        } else {
            if ($contact->isTrashed()) {
                $contact->untrash();
            }
        }
        $contact->setFirstname($user->getDisplayName());
        $contact->setUserId($user->getId());
        $contact->setTimezone($user->getTimezone());
        $contact->setCompanyId($user->getCompanyId());
        $contact->save();
    } else {
        $contact_id = array_var($user_data, 'contact_id');
        $contact = Contacts::findById($contact_id);
        if ($contact instanceof Contact) {
            // user created from a contact
            $contact->setUserId($user->getId());
            $contact->save();
        } else {
            // if contact with same email exists use it as user's contact, without changing it
            $contact = Contacts::getByEmail($user->getEmail(), true);
            if ($contact instanceof Contact) {
                $contact->setUserId($user->getId());
                if ($contact->isTrashed()) {
                    $contact->untrash();
                }
                $contact->save();
            }
        }
    }
    $contact = $user->getContact();
    if ($contact instanceof Contact) {
        // update contact data with data entered for this user
        $contact->setCompanyId($user->getCompanyId());
        if ($contact->getEmail() != $user->getEmail()) {
            // make user's email the contact's main email address
            if ($contact->getEmail2() == $user->getEmail()) {
                $contact->setEmail2($contact->getEmail());
            } else {
                if ($contact->getEmail3() == $user->getEmail()) {
                    $contact->setEmail3($contact->getEmail());
                } else {
                    if ($contact->getEmail2() == "") {
                        $contact->setEmail2($contact->getEmail());
                    } else {
                        $contact->setEmail3($contact->getEmail());
                    }
                }
            }
        }
        $contact->setEmail($user->getEmail());
        $contact->save();
    }
    if (!$user->isGuest()) {
        /* create personal project or assing the selected*/
        //if recived a personal project assing this
        //project as personal project for this user
        $new_project = null;
        $personalProjectId = array_var($user_data, 'personal_project', 0);
        $project = Projects::findById($personalProjectId);
        if (!$project instanceof Project) {
            $project = new Project();
            $wname = new_personal_project_name($user->getUsername());
            $project->setName($wname);
            $wdesc = Localization::instance()->lang(lang('personal workspace description'));
            if (!is_null($wdesc)) {
                $project->setDescription($wdesc);
            }
            $project->setCreatedById($user->getId());
            $project->save();
            //Save to set an ID number
            $project->setP1($project->getId());
            //Set ID number to the first project
            $project->save();
            $new_project = $project;
        }
        $user->setPersonalProjectId($project->getId());
        $project_user = new ProjectUser();
        $project_user->setProjectId($project->getId());
        $project_user->setUserId($user->getId());
        $project_user->setCreatedById($user->getId());
        $project_user->setAllPermissions(true);
        $project_user->save();
        /* end personal project */
    }
    $user->save();
    ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
    //TODO - Make batch update of these permissions
    if ($permissionsString && $permissionsString != '') {
        $permissions = json_decode($permissionsString);
    } else {
        $permissions = null;
    }
    if (is_array($permissions) && (!logged_user() instanceof User || can_manage_security(logged_user()))) {
        foreach ($permissions as $perm) {
            if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                if (!$personalProjectId || $personalProjectId != $perm->wsid) {
                    $relation = new ProjectUser();
                    $relation->setProjectId($perm->wsid);
                    $relation->setUserId($user->getId());
                    $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true);
                    $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true);
                    $relation->save();
                }
            }
        }
    }
    // if
    if ($new_project instanceof Project && logged_user() instanceof User && logged_user()->isProjectUser($new_project)) {
        evt_add("workspace added", array("id" => $new_project->getId(), "name" => $new_project->getName(), "color" => $new_project->getColor()));
    }
    // Send notification...
    try {
        if (array_var($user_data, 'send_email_notification')) {
            Notifier::newUserAccount($user, $password);
        }
        // if
    } catch (Exception $e) {
    }
    // try
    return $user;
}
Ejemplo n.º 13
0
 /**
  * Create a contact with the data of a user
  *
  */
 function create_contact_from_user()
 {
     ajx_current("empty");
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         return;
     }
     // if
     if (!logged_user()->canSeeUser($user)) {
         flash_error(lang('no access permissions'));
         return;
     }
     // if
     if ($user->getContact()) {
         if ($contact->isTrashed()) {
             try {
                 DB::beginWork();
                 $contact->untrash();
                 DB::commit();
                 $this->redirectTo('contact', 'card', array('id' => $contact->getId()));
             } catch (Exception $e) {
                 DB::rollback();
                 flash_error(lang('error add contact from user') . " " . $e->getMessage());
             }
         } else {
             flash_error(lang('user has contact'));
             return;
         }
     }
     try {
         DB::beginWork();
         $contact = new Contact();
         $contact->setFirstname($user->getDisplayName());
         $contact->setUserId($user->getId());
         $contact->setEmail($user->getEmail());
         $contact->setTimezone($user->getTimezone());
         $contact->setCompanyId($user->getCompanyId());
         $contact->save();
         DB::commit();
         $this->redirectTo('contact', 'card', array('id' => $contact->getId()));
     } catch (Exception $exx) {
         DB::rollback();
         flash_error(lang('error add contact from user') . " " . $exx->getMessage());
     }
 }
<?php

require_once './classes/Prepavenir/Entity/Societe.php';
require_once './classes/Prepavenir/Entity/Contact.php';
$darty = new Societe();
$darty->setNom('Darty');
$darty->setVille('Sannois');
$contact = new Contact();
$contact->setPrenom('Eric');
$contact->setNom('Martin');
$contact->setEmail('*****@*****.**');
$contact->setTelephone('01 35 67 84 56');
$contact->setSociete($darty);
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Détails d'un contact</title>
    </head>
    <body>
        <h2>Détails d'un contact</h2>
        <table>
            <tr>
                <th>Prénom</th>
                <td><?php 
echo $contact->getPrenom();
?>
</td>
            </tr>
            <tr>