public static function Save(Affiliation $dbAffiliation, $newAffiliation, $org_name, Member $CurrentMember)
 {
     $org_name = Convert::raw2sql($org_name);
     // attempt to retrieve Org by the submitted name
     $org = Org::get()->filter('Name', $org_name)->First();
     if (!$org) {
         // no org matched, create a new org of that name and associate it
         $org = new Org();
         $org->Name = $org_name;
         $org->write();
     }
     $config = HTMLPurifier_Config::createDefault();
     // Remove any CSS or inline styles
     $config->set('CSS.AllowedProperties', array());
     $purifier = new HTMLPurifier($config);
     $dbAffiliation->OrganizationID = $org->ID;
     $dbAffiliation->JobTitle = $newAffiliation->JobTitle;
     $dbAffiliation->MemberID = $CurrentMember->ID;
     $dbAffiliation->StartDate = $newAffiliation->StartDate;
     $dbAffiliation->EndDate = !empty($newAffiliation->EndDate) ? $newAffiliation->EndDate : null;
     $dbAffiliation->Current = $newAffiliation->Current == 1 ? true : false;
     if (empty($newAffiliation->EndDate)) {
         $dbAffiliation->Current = true;
     }
     $dbAffiliation->write();
 }
 /**
  * @param string $name
  * @param null|string $foundation_support_level
  * @return IOrganization
  */
 public function build($name, $foundation_support_level = null)
 {
     $org = Org::create();
     $org->Name = trim($name);
     if (!is_null($foundation_support_level)) {
         $org->FoundationSupportLevel = $foundation_support_level;
     }
     return $org;
 }
 public static function Save(Affiliation $dbAffiliation, $newAffiliation, $org_name, Member $CurrentMember)
 {
     $org_name = Convert::raw2sql($org_name);
     // attempt to retrieve Org by the submitted name
     $org = Org::get()->filter('Name', $org_name)->First();
     if (!$org) {
         // no org matched, create a new org of that name and associate it
         $org = new Org();
         $org->Name = $org_name;
         $org->write();
         //register new request
         $new_request = new OrganizationRegistrationRequest();
         $new_request->MemberID = $CurrentMember->ID;
         $new_request->OrganizationID = $org->ID;
         $new_request->write();
     }
     $config = HTMLPurifier_Config::createDefault();
     // Remove any CSS or inline styles
     $config->set('CSS.AllowedProperties', array());
     $purifier = new HTMLPurifier($config);
     if (!empty($newAffiliation->EndDate) && $newAffiliation->Current == 1) {
         $today = new DateTime($newAffiliation->ClientToday);
         $end_date = new DateTime($newAffiliation->EndDate);
         if ($end_date < $today) {
             throw new Exception('Current Affiliation: End Date must me greater than today!.');
         }
     }
     $dbAffiliation->OrganizationID = $org->ID;
     $dbAffiliation->MemberID = $CurrentMember->ID;
     $dbAffiliation->StartDate = $newAffiliation->StartDate;
     $dbAffiliation->EndDate = !empty($newAffiliation->EndDate) ? $newAffiliation->EndDate : null;
     $dbAffiliation->Current = $newAffiliation->Current == 1 ? true : false;
     if (empty($newAffiliation->EndDate)) {
         $dbAffiliation->Current = true;
     }
     //$dbAffiliation->JobTitle = $purifier->purify($newAffiliation->JobTitle);
     //$dbAffiliation->Role      = $purifier->purify($newAffiliation->Role);
     $dbAffiliation->write();
 }
 public function __construct(ISingleValueTemplateQuestion $question, $value = null)
 {
     $children = new FieldList();
     $this->question = $question;
     $current_user = Member::currentUser();
     $current_affiliations = $current_user->getCurrentAffiliations();
     if (!$current_affiliations) {
         $children->add($txt = new TextField($question->name(), $question->label()));
         $txt->addExtraClass('input-organization-name');
     } else {
         if (intval($current_affiliations->count()) > 1) {
             $source = array();
             foreach ($current_affiliations as $a) {
                 $org = $a->Organization();
                 $source[$org->ID] = $org->Name;
             }
             $source['0'] = "-- New One --";
             $children->add($ddl = new DropdownField($question->name() . 'ID', $question->label(), $source));
             $ddl->setEmptyString('-- Select Your Organization --');
             $ddl->addExtraClass('select-organization-name');
             if (!is_null($value)) {
                 $org = Org::get()->filter('Name', $value)->first();
                 if ($org) {
                     $ddl->setValue($org->ID);
                 }
             }
             $children->add($txt = new TextField($question->name(), ''));
             $txt->addExtraClass('input-organization-name');
         } else {
             $children->add($txt = new TextField($question->name(), $question->label(), $current_user->getOrgName()));
             $txt->addExtraClass('input-organization-name');
         }
     }
     parent::__construct($children);
     $control_css_class = strtolower($this->question->name() . '-composite');
     $this->addExtraClass($control_css_class);
     Requirements::javascript('survey_builder/js/survey.organization.field.js');
     Requirements::customScript("\n        jQuery(document).ready(function(\$) {\n            \$('.'+'{$control_css_class}').survey_organization_field();\n        });");
 }
Example #5
0
 /**
  * Send  SMS
  */
 public static function send()
 {
     $recipients = SmsHandler::$model->recipients;
     $settings = Yii::app()->settings->get(Constants::CATEGORY_SMS, array(Constants::KEY_SMS_AFRICASTALKING_USERNAME, Constants::KEY_SMS_AFRICASTALKING_API_KEY, Constants::KEY_SMS_AFRICASTALKING_SHORTCORD));
     if (!is_array($recipients)) {
         $recipients = explode(',', $recipients);
     }
     if (empty(SmsHandler::$model->from)) {
         SmsHandler::$model->from = $settings[Constants::KEY_SMS_AFRICASTALKING_SHORTCORD];
     }
     $gateway = new AfricaStalkingGateway($settings[Constants::KEY_SMS_AFRICASTALKING_USERNAME], $settings[Constants::KEY_SMS_AFRICASTALKING_API_KEY]);
     $recipients_count = count($recipients);
     $sent_count = 0;
     SmsHandler::$model->batch_id = MsgSmsOutbox::model()->getNextIntegerID('batch_id');
     $success_count = 0;
     $chunks = SmsHandler::getChunks($recipients, self::MAX_CHUNK_LENGTH, $recipients_count);
     $currency = Yii::app()->settings->get(Constants::CATEGORY_GENERAL, Constants::KEY_CURRENCY, SettingsCurrency::CURRENCY_KES);
     $org_model = !empty(SmsHandler::$model->org_id) ? Org::model()->loadModel(SmsHandler::$model->org_id) : NULL;
     $price_per_sms = NULL !== $org_model ? $org_model->price_per_sms : NULL;
     foreach ($chunks as $contacts) {
         $error = FALSE;
         $status_message = NULL;
         if (SmsHandler::$model->recipients_source === MsgSmsOutbox::RECIPIENTS_SOURCE_DEFAULT) {
             $gsm_numbers = SmsHandler::preparePhoneNumbers($contacts, FALSE);
         } else {
             $gsm_numbers = implode(",", $contacts);
         }
         $results = $gateway->sendMessage($gsm_numbers, SmsHandler::$model->message, SmsHandler::$model->from);
         if (empty($results)) {
             $status_message = "Oops, No messages were sent. ErrorMessage: " . $gateway->getErrorMessage();
             $error = TRUE;
         }
         if (!empty(SmsHandler::$queue_id)) {
             if ($error === FALSE) {
                 $sent_count = $sent_count + count($contacts);
                 $status_message = Lang::t("Processed {$sent_count} of {$recipients_count} messages");
             }
             ConsoleTaskQueue::model()->updateProgress(SmsHandler::$queue_id, $status_message);
             //update status
         } else {
             if ($error === TRUE && NULL !== $status_message) {
                 Yii::log($status_message, CLogger::LEVEL_ERROR);
             }
         }
         if ($error === FALSE) {
             $success_count += self::saveRecipients(SmsHandler::$model, $results, $currency, $price_per_sms);
         }
         sleep(1);
     }
     if (NULL !== $org_model) {
         SmsHandler::addBilling($org_model, SmsHandler::$model, $success_count);
     }
     if (!empty(SmsHandler::$queue_id)) {
         ConsoleTaskQueue::model()->updateProgress(SmsHandler::$queue_id, Lang::t('Completed.'), ConsoleTaskQueue::STATUS_COMPLETED);
     }
 }
Example #6
0
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
PublisherSubscriberManager::getInstance()->subscribe('survey_organization_selected', function ($member, $organization_name) {
    //create the affiliation as current
    $organization_name = Convert::raw2sql(trim($organization_name));
    if (!empty($organization_name)) {
        $org = Org::get()->filter(array('Name' => $organization_name))->first();
        if (!$org) {
            $org = new Org();
            $org->Name = $organization_name;
            $org->IsStandardizedOrg = false;
            $org->write();
            //register new request
            $new_request = new OrganizationRegistrationRequest();
            $new_request->MemberID = $member->getIdentifier();
            $new_request->OrganizationID = $org->ID;
            $new_request->write();
        }
        // If a new org name was provided for the member, find / create the new org and update the member record
        if (!$member->hasCurrentAffiliation($organization_name)) {
            $newAffiliation = new StdClass();
            $newAffiliation->StartDate = date('Y-m-d');
            $newAffiliation->EndDate = null;
            $newAffiliation->Current = 1;
 public function results()
 {
     if ($query = $this->getSearchQuery()) {
         $query = Convert::raw2xml($query);
         // Search Orgs against the query.
         $Results = Org::get()->filter('Name:PartialMatch', $query);
         // For AutoComplete
         if (Director::is_ajax() && $Results) {
             $Orgs = $Results->map('ID', 'Name');
             $Suggestions = "";
             foreach ($Orgs as $Org) {
                 $Suggestions = $Suggestions . $Org . '|' . '1' . "\n";
             }
             return $Suggestions;
         }
     }
 }
 /**
  * @remotable
  * @formHandler
  */
 public function doSignup($params)
 {
     //check unique email address
     $q = Doctrine_Query::create()->select('u.email')->from('User u')->where('u.email = ?', $params['email']);
     $q->execute();
     $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
     if (sizeof($result) > 0) {
         return array("success" => false, "msg" => "You're email address has already been registered. Please choose a different email address.");
     }
     /*		
     		foreach ($result as $key => $value) {
     			if($value['email'] == $params['email']){
     			}
     		}
     */
     //check unique login
     $q = Doctrine_Query::create()->select('u.login')->from('User u')->where('u.login = ?', $params['login']);
     $q->execute();
     $result = $q->execute(array(), Doctrine::HYDRATE_ARRAY);
     if ($result) {
         return array("success" => false, "msg" => "This login is already taken. Please use another login.");
     }
     //update org table
     $org = new Org();
     $org->orgName = $params['orgName'];
     $org->zip = $params['zip'];
     $org->rTime = date("Y-m-d : H:i:s", time());
     $org->save();
     //echo $org->ID;
     //update contact_value table
     $contactValue = new ContactValue();
     $contactValue->orgID = $org->ID;
     $contactValue->firstName = $params['firstName'];
     $contactValue->lastName = $params['lastName'];
     $contactValue->email = $params['email'];
     $contactValue->type = "1";
     $contactValue->rTime = date("Y-m-d : H:i:s", time());
     $contactValue->save();
     //update user table
     $user = new User();
     $user->orgID = $org->ID;
     $user->login = $params['login'];
     $user->password = $params['password'];
     $user->email = $params['email'];
     $user->userRoleID = 1;
     $user->contactID = $contactValue->ID;
     $user->rUser = $user->ID;
     $user->rTime = date("Y-m-d : H:i:s", time());
     $user->save();
     //server full path
     $fullPath = $_SERVER["REQUEST_URI"];
     //detect environments
     if (stristr($fullPath, "uat")) {
         $host = "https://" . $_SERVER['SERVER_NAME'] . "/uat/moqoldWeb/";
     } elseif (stristr($fullPath, "moqoldWeb")) {
         $host = "https://" . $_SERVER['SERVER_NAME'] . "/moqoldWeb/";
     } else {
         $host = "https://" . $_SERVER['SERVER_NAME'] . "/";
     }
     $subject = "mOQOLD Activation Notification";
     $message = "Hello ";
     $message .= $params['firstName'] . " " . $params['lastName'] . " from mOQOLD,<br><br>";
     $message .= "Congratulations! Thank you for signing up to use the mOQOLD \r\n\t\t             (<a href='http://www.moqold.com/moqoldWeb/index.html'>www.moqold.com</a>) site. \r\n\t\t             Please note -you must complete this last step to activate \r\n\t\t             your account and become a user of the website.<br><br>";
     $message .= "Please click on this link below:<br><a href='";
     $message .= $host;
     $message .= "index.html#Confirm'>" . $host . "index.html#Confirm</a><br><br>";
     $message .= "You'll be asked to enter your email address and password, and \r\n    \t\t\t\tthen we will activate your account to allow you to start using \r\n    \t\t\t\tthe website. If you are unable to activate your account by clicking \r\n    \t\t\t\ton the link above, please copy and paste the entire URL below into \r\n    \t\t\t\tyour web browser. Once the account has been activated, we recommend \r\n    \t\t\t\tyou flow the wizard if you are the first person in your organization \r\n    \t\t\t\tusing the site. ";
     $message .= "Do not reply to this automatically-generated email. If you have any \r\n    \t\t\t\tquestions or problems, please email us at \r\n    \t\t\t\t<a href='mailto:support@moqold.com'>support@moqold.com</a>.<br><br>";
     $message .= "All the best,<br>mOQOLD Support Team<br><br>";
     //print the footer
     $message .= "<hr size='2' color='#000000'><br>";
     $message .= "<a href='http://www.moqold.com/moqoldWeb/index.html'>Home</a> | \r\n    \t             <a href='http://www.moqold.com/moqoldWeb/index.html#Static|page=WhatIsmOQOLD'>What is mOQOLD?</a> |\r\n    \t             <a href='http://www.moqold.com/moqoldWeb/index.html#Static|page=Help'>Get Help </a> |\r\n    \t             <a href='http://www.moqold.com/moqoldWeb/index.html#Static|page=Security'>Privacy</a> |\r\n    \t             <a href='http://www.moqold.com/moqoldWeb/index.html#Static|page=Terms'>Terms of Use</a>";
     $this->sendMail($params['email'], $subject, $message);
     $this->currentUser = $user;
     return array("success" => true, "msg" => $message);
 }
 /**
  * @param $request
  * @return SS_HTTPResponse
  */
 public function searchOrg($request)
 {
     if (!Director::is_ajax()) {
         return $this->forbiddenError();
     }
     $term = $request->getVar('term');
     $term = Convert::raw2sql($term);
     $organizations = Org::get()->filter('Name:PartialMatch', $term)->limit(10);
     if ($organizations) {
         $suggestions = array();
         foreach ($organizations as $org) {
             array_push($suggestions, array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name));
         }
         $response = new SS_HTTPResponse();
         $response->setStatusCode(200);
         $response->addHeader('Content-Type', 'application/json');
         $response->setBody(json_encode($suggestions));
         return $response;
     }
 }
 public function NextStep($data, $form)
 {
     // Save our work
     $survey = $this->GetCurrentSurvey();
     $form->saveInto($survey);
     //Update Member if need be
     if (isset($data['Organization'])) {
         $org_data = Convert::raw2sql(trim($data['Organization']));
         if (!empty($org_data)) {
             $org = Org::get()->filter(array('Name' => $org_data))->first();
             if (!$org) {
                 $org = new Org();
                 $org->Name = $org_data;
                 $org->IsStandardizedOrg = false;
                 $org->write();
                 //register new request
                 $new_request = new OrganizationRegistrationRequest();
                 $new_request->MemberID = Member::currentUserID();
                 $new_request->OrganizationID = $org->ID;
                 $new_request->write();
             }
             $this->updateMember($org_data);
             $survey->OrgID = $org->ID;
             $survey->UpdateDate = SS_Datetime::now()->Rfc2822();
             $survey->write();
         }
     }
     $newIndex = array_search($this->CurrentStep(), DeploymentSurvey::$steps) + 1;
     if ($form instanceof DeploymentSurveyAboutYouForm) {
         //check if user info has changed
         $current_user = Member::currentUser();
         $current_user->FirstName = $data['FirstName'];
         $current_user->Surname = $data['Surname'];
         $current_user->write();
     }
     if ($form instanceof DeploymentSurveyYourThoughtsForm) {
         if (strpos($survey->OpenStackActivity, 'Write applications that run on OpenStack') !== false || strpos($survey->OpenStackActivity, 'Manage people who write applications that run on OpenStack') !== false || strpos($survey->OpenStackInvolvement, 'Cloud Consumer') !== false) {
             //normal flow - Send them to user-survey/AppDevSurvey as normal
             $newIndex = array_search('AppDevSurvey', DeploymentSurvey::$steps);
         } else {
             //  Send them to user-survey/Deployments
             $newIndex = array_search('Deployments', DeploymentSurvey::$steps);
         }
     }
     if ($newIndex > count(DeploymentSurvey::$steps)) {
         $newIndex = count(DeploymentSurvey::$steps);
     }
     $CurrentStep = DeploymentSurvey::$steps[$newIndex];
     Session::set('CurrentStep', $CurrentStep);
     $survey->CurrentStep = $CurrentStep;
     $DesiredHighestStepIndex = array_search($survey->CurrentStep, DeploymentSurvey::$steps);
     // The index of this step in the list
     $HighestStepAllowedIndex = array_search($survey->HighestStepAllowed, DeploymentSurvey::$steps);
     // The index of the highest allowed step in the list
     if ($DesiredHighestStepIndex > $HighestStepAllowedIndex) {
         $survey->HighestStepAllowed = $CurrentStep;
     }
     $survey->UpdateDate = SS_Datetime::now()->Rfc2822();
     $survey->write();
     $this->redirect($this->Link() . $CurrentStep);
 }
 /**
  * @param string $name
  * @return IOrganization
  */
 public function getByName($name)
 {
     return Org::get()->filter('Name', $name)->First();
 }
 public function suggestOrganization(SS_HTTPRequest $request)
 {
     if (!Director::is_ajax()) {
         return $this->forbiddenError();
     }
     if (!Member::currentUser()) {
         return $this->forbiddenError();
     }
     $term = Convert::raw2sql($request->getVar('term'));
     $orgs = Org::get()->filter('Name:PartialMatch', $term)->sort('Name')->limit(100);
     $items = array();
     foreach ($orgs as $org) {
         $items[] = array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name);
     }
     return $this->ok($items);
 }
 public function suggestOrganization(SS_HTTPRequest $request)
 {
     if (!Director::is_ajax()) {
         return $this->httpError(403);
     }
     if (!Member::currentUser()) {
         return $this->httpError(403);
     }
     $term = Convert::raw2sql($request->getVar('term'));
     $orgs = Org::get()->filter('Name:PartialMatch', $term)->sort('Name')->limit(100);
     $items = array();
     foreach ($orgs as $org) {
         $items[] = array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name);
     }
     $response = new SS_HTTPResponse();
     $response->addHeader('Content-Type', 'application/json');
     $response->setBody(json_encode($items));
     return $response;
 }