function setUp()
 {
     global $db, $timedate, $current_user;
     $this->original_current_user = $current_user;
     $user = new User();
     $user->retrieve('1');
     $current_user = $user;
     if ($db->dbType != 'mysql') {
         $this->markTestSkipped('Skipping for non-mysql dbs');
     }
     $this->meeting = SugarTestMeetingUtilities::createMeeting();
     $date_start = $timedate->nowDb();
     $this->meeting->date_start = $date_start;
     $this->meeting->duration_hours = 2;
     $this->meeting->duration_minutes = 30;
     $this->meeting->save();
     $sql = "UPDATE meetings SET date_end = '{$date_start}' WHERE id = '{$this->meeting->id}'";
     $db->query($sql);
     $this->call = SugarTestCallUtilities::createCall();
     $date_start = $timedate->nowDb();
     $this->call->date_start = $date_start;
     $this->call->duration_hours = 2;
     $this->call->duration_minutes = 30;
     $this->call->save();
     $sql = "UPDATE calls SET date_end = '{$date_start}' WHERE id = '{$this->call->id}'";
     $db->query($sql);
 }
 function test_login_ends_in_equals()
 {
     $user = User::create('foo=');
     $this->assertFalse(is_null($user));
     $user2 = User::retrieve('foo=');
     $this->assertFalse(is_null($user2));
 }
function CustomScheduler()
{
    global $sugar_config, $db;
    $timeDate = new TimeDate();
    $timeDateNow = $timeDate->getNow(true)->asDb();
    $days_offset = 15;
    $GLOBALS['log']->fatal("Checking Opportunities...");
    $query = "select opportunities.id from opportunities\n\twhere opportunities.sales_stage != 'Closed Won'\n\tand DATEDIFF(opportunities.date_modified,'" . $timeDateNow . "') < " . $days_offset . "\n\tand !opportunities.deleted";
    $GLOBALS['log']->fatal("Query: " . $query);
    $res = $db->query($query, true, 'Error: ');
    while ($row = $db->fetchByAssoc($res)) {
        $opportunity = new Opportunity();
        if (!is_null($opportunity->retrieve($row['id']))) {
            $user = new User();
            if (!is_null($user->retrieve($opportunity->assigned_user_id))) {
                $emailsTo = array();
                $emailSubject = "Opportunity Alert";
                $emailBody = "The following Opportunity has " . $days_offset . " days without changes.<br /><br />\n\t\t\t\tName: " . $opportunity->name . "<br />\n\t\t\t\tAccount: " . $opportunity->account_name . "<br />\n\t\t\t\tAmount: " . $opportunity->amount . "<br />\n\t\t\t\tSales Stage: " . $opportunity->sales_stage . "<br />\n\t\t\t\tDate Close: " . $opportunity->date_closed . "<br /><br />\n\t\t\t\tYou can see the opportunity here:<br />\n\t\t\t\t<a href=\"" . $sugar_config['site_url'] . "/index.php?module=Opportunities&action=DetailView&record=" . $opportunity->id . "\">" . $opportunity->name . "</a>";
                $emailsTo[] = $user->email1;
                SendEmail($emailsTo, $emailSubject, $emailBody);
            }
        }
    }
    $GLOBALS['log']->fatal("Opportunities checked");
    return true;
}
 /**
  * Validate the provided session information is correct and current.  Load the session.
  *
  * @param String $session_id -- The session ID that was returned by a call to login.
  * @return true -- If the session is valid and loaded.
  * @return false -- if the session is not valid.
  */
 function validate_authenticated($session_id)
 {
     $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated');
     if (!empty($session_id)) {
         // only initialize session once in case this method is called multiple times
         if (!session_id()) {
             session_id($session_id);
             session_start();
         }
         if (!empty($_SESSION['is_valid_session']) && $this->is_valid_ip_address('ip_address') && $_SESSION['type'] == 'user') {
             global $current_user;
             require_once 'modules/Users/User.php';
             $current_user = new User();
             $current_user->retrieve($_SESSION['user_id']);
             $this->login_success();
             $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated - passed');
             $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated');
             return true;
         }
         $GLOBALS['log']->debug("calling destroy");
         session_destroy();
     }
     LogicHook::initialize();
     $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed');
     $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated - validation failed');
     return false;
 }
function authenticate()
{
    global $sugar_config;
    $user_unique_key = isset($_SESSION['unique_key']) ? $_SESSION['unique_key'] : "";
    $server_unique_key = isset($sugar_config['unique_key']) ? $sugar_config['unique_key'] : "";
    if ($user_unique_key != $server_unique_key) {
        $GLOBALS['log']->debug("JSON_SERVER: user_unique_key:" . $user_unique_key . "!=" . $server_unique_key);
        session_destroy();
        return null;
    }
    if (!isset($_SESSION['authenticated_user_id'])) {
        $GLOBALS['log']->debug("JSON_SERVER: authenticated_user_id NOT SET. DESTROY");
        session_destroy();
        return null;
    }
    $current_user = new User();
    $result = $current_user->retrieve($_SESSION['authenticated_user_id']);
    $GLOBALS['log']->debug("JSON_SERVER: retrieved user from SESSION");
    if ($result == null) {
        $GLOBALS['log']->debug("JSON_SERVER: could get a user from SESSION. DESTROY");
        session_destroy();
        return null;
    }
    return $result;
}
 function displayList(&$layout_def)
 {
     global $app_strings;
     global $subpanel_item_count;
     $unique_id = $layout_def['subpanel_id'] . "_remove_" . $subpanel_item_count;
     //bug 51512
     $parent_record_id = $_REQUEST['record'];
     $parent_module = $_REQUEST['module'];
     $action = 'DeleteRelationship';
     $record = $layout_def['fields']['ID'];
     $current_module = $layout_def['module'];
     //in document revisions subpanel ,users are now allowed to
     //delete the latest revsion of a document. this will be tested here
     //and if the condition is met delete button will be removed.
     $hideremove = false;
     if ($current_module == 'DocumentRevisions') {
         if ($layout_def['fields']['ID'] == $layout_def['fields']['LATEST_REVISION_ID']) {
             $hideremove = true;
         }
     } elseif ($_REQUEST['module'] == 'Teams' && $current_module == 'Users') {
         if ($layout_def['fields']['UPLINE'] != translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) {
             $hideremove = true;
         }
         //We also cannot remove the user whose private team is set to the parent_record_id value
         $user = new User();
         $user->retrieve($layout_def['fields']['ID']);
         if ($parent_record_id == $user->getPrivateTeamID()) {
             $hideremove = true;
         }
     }
     $return_module = $_REQUEST['module'];
     $return_action = 'SubPanelViewer';
     $subpanel = $layout_def['subpanel_id'];
     $return_id = $_REQUEST['record'];
     if (isset($layout_def['linked_field_set']) && !empty($layout_def['linked_field_set'])) {
         $linked_field = $layout_def['linked_field_set'];
     } else {
         $linked_field = $layout_def['linked_field'];
     }
     $refresh_page = 0;
     if (!empty($layout_def['refresh_page'])) {
         $refresh_page = 1;
     }
     $return_url = "index.php?module={$return_module}&action={$return_action}&subpanel={$subpanel}&record={$return_id}&sugar_body_only=1&inline=1";
     $icon_remove_text = strtolower($app_strings['LBL_ID_FF_REMOVE']);
     if ($linked_field == 'get_products_query') {
         $linked_field = 'products';
     } else {
         if ($linked_field == 'get_emails_by_assign_or_link') {
             $linked_field = 'emails';
         }
     }
     //based on listview since that lets you select records
     if ($layout_def['ListView'] && !$hideremove) {
         $retStr = "<a href=\"javascript:sub_p_rem('{$subpanel}', '{$linked_field}'" . ", '{$record}', {$refresh_page});\"" . ' class="listViewTdToolsS1"' . "id={$unique_id}" . " onclick=\"return sp_rem_conf();\"" . ">{$icon_remove_text}</a>";
         return $retStr;
     } else {
         return '';
     }
 }
Example #7
0
function _ops_update()
{
    require_login();
    $msg = '';
    $uid = max(0, intval($_POST['uid']));
    $user = new User();
    if ($uid) {
        $user->retrieve($uid);
        $user->merge($_POST);
        if (!$user->exists()) {
            $msg = 'User not found!';
        } else {
            if ($user->update()) {
                $msg = 'User updated!';
            } else {
                $msg = 'User update failed!';
            }
        }
    } else {
        $user->merge($_POST);
        if ($user->create()) {
            $msg = 'User inserted!';
        } else {
            $msg = 'User insert failed!';
        }
    }
    redirect('users/manage', $msg);
}
 function get_list_view_data()
 {
     $data = parent::get_list_view_data();
     $delete = '';
     $group_owner = false;
     $securitygroup_name = "";
     if (empty($data['SECURITYGROUP_ID'])) {
         $securitygroup_name = "All";
     } else {
         require_once 'modules/SecurityGroups/SecurityGroup.php';
         $securitygroup = new SecurityGroup();
         $securitygroup->retrieve($data['SECURITYGROUP_ID']);
         $securitygroup_name = $securitygroup->name;
         if ($securitygroup->assigned_user_id == $GLOBALS['current_user']->id) {
             $group_owner = true;
         }
     }
     if (is_admin($GLOBALS['current_user']) || $data['CREATED_BY'] == $GLOBALS['current_user']->id || $group_owner) {
         $delete = SugarThemeRegistry::current()->getImage('delete_inline', 'width="12" height="12" border="0" align="absmiddle" style="vertical-align: bottom;" onclick=\'Message.deleteMessage("' . $data['ID'] . '", "{this.id}")\'', null, null, '.gif', '');
     }
     $username = "";
     if (empty($data['CREATED_BY'])) {
         $username = "******";
     } else {
         require_once 'modules/Users/User.php';
         $user = new User();
         $user->retrieve($data['CREATED_BY']);
         $username = $user->user_name;
     }
     $data['NAME'] = $data['DESCRIPTION'];
     $data['NAME'] = '<div class="list view" style="padding:5px;border:none;">' . html_entity_decode($data['NAME']);
     $data['NAME'] .= '<div class="byLineBox" style="padding-top: 2px"><span class="byLineLeft">' . $username . ' [' . $securitygroup_name . ']';
     $data['NAME'] .= '&nbsp;</span><span style="cursor: pointer;" class="byLineRight"> ' . $this->getTimeLapse($data['DATE_ENTERED']) . ' &nbsp;' . $delete . '</span></div>';
     return $data;
 }
Example #9
0
function NoActiveRealtyNotifier()
{
    global $db;
    $sql = "SELECT name, date_modified, id, assigned_user_id FROM realty WHERE deleted = 0";
    $result = $db->query($sql);
    $realty_arr = array();
    while ($row = $db->fetchByAssoc($result)) {
        $realty_arr[$row['id']] = array('date' => $row['date_modified'], 'name' => $row['name'], 'assigned_user_id' => $row['assigned_user_id']);
    }
    $time_interval = 5;
    $current_date = time();
    foreach ($realty_arr as $id => $var) {
        $unix_time_date_entered = strtotime($var['date']);
        $interval = $current_date - $unix_time_date_entered;
        if ($interval >= $time_interval and $interval > 0) {
            $querry = "UPDATE realty SET activity_status = 'no_active' WHERE id = '{$id}'";
            $db->query($querry);
            require_once "custom/include/send_mail/send_mail.php";
            $user = new User();
            $user->retrieve($var['assigned_user_id']);
            $link = "http://" . $_SERVER['HTTP_HOST'] . "/index.php?module=Realty&action=DetailView&record=" . $id;
            $body = "Здравствуйте {$user->last_name} {$user->first_name} ! <br/>\n                 Из-за того, что c недвижимостью <a href='{$link}'>" . $var['name'] . "</a>\n                 не проводилось никаких действий 2 недели, ее статус в системе стал неактивным.";
            sendSugarPHPMail(array('0' => '*****@*****.**'), 'Недвижимость перешла в статус "неактивна"', $body);
        }
    }
    return true;
}
Example #10
0
 function addTab(&$bean, $event)
 {
     global $current_user;
     //make sure this only runs on a Users Edit or Detail view
     if ($_REQUEST['module'] == 'Users' && !empty($_REQUEST['record']) && ($_REQUEST['action'] == 'EditView' || $_REQUEST['action'] == 'DetailView')) {
         //$mod_strings = return_module_language($GLOBALS['current_language'], 'Users');
         //require_once('custom/modules/Users/homepage_manager.php');
         $focus = new User();
         $focus->retrieve($_REQUEST['record']);
         $dd = new defaultHomepage();
         $defaultHomepage = $focus->hm_default_homepage_c;
         $onlyOnce = $focus->hm_only_once_c;
         $lockOptions = $dd->getLockOptions($focus->hm_lockhomepage_c);
         if ($onlyOnce == '1') {
             $onlyOnce = "checked";
         } else {
             $onlyOnce = "";
         }
         $defaultHomepageOptions = $dd->getAllDashboardOptions($focus->id, $defaultHomepage);
         if ($_REQUEST['action'] == 'EditView' && $current_user->is_admin) {
             echo "<script type=\"text/javascript\">\n\t\t\t\tvar EditView_tabs = new YAHOO.widget.TabView(\"EditView_tabs\");\n\t\t\t\tEditView_tabs.on('contentReady', function(e){\n\t\t\t\tEditView_tabs.addTab( new YAHOO.widget.Tab({\n\t\t\t\tlabel: 'Dashlet Manager',\n\t\t\t\tcontent: '" . $this->createFormHTML($onlyOnce, $lockOptions, $defaultHomepageOptions) . "',\n\t\t\t\tcacheData: true\n\t\t\t\t}));\n\t\t\t\t});\n\t\t\t\t</script> \n";
         }
         if ($_REQUEST['action'] == 'DetailView') {
             echo "<script type=\"text/javascript\">\n\t\t\t\tvar DetailView_tabs = new YAHOO.widget.TabView(\"user_detailview_tabs\");\n\t\t\t\tDetailView_tabs.on('contentReady', function(e){\n\t\t\t\tDetailView_tabs.addTab( new YAHOO.widget.Tab({\n\t\t\t\tlabel: 'Dashlet Manager',\n\t\t\t\tcontent: '" . $this->createFormHTML($onlyOnce, $lockOptions, $defaultHomepageOptions) . "',\n\t\t\t\tcacheData: true\n\t\t\t\t}));\n\t\t\t\t});\n\t\t\t\t</script> \n";
         }
     }
 }
Example #11
0
 function panel()
 {
     $this->load->model('user');
     $this->load->model('script');
     $this->load->library('facebook');
     if ($signedUp = $this->session->flashdata('signedUp')) {
         $this->session->keep_flashdata('signedUp');
         $viewData['signedUp'] = $signedUp;
     }
     if ($this->input->post('changePassword')) {
         if ($this->_checkToken()) {
             $this->load->library('validation');
             $rules['currentPassword'] = '******';
             $rules['newPassword'] = '******';
             $rules['newPasswordRepeat'] = 'required|matches[newPassword]';
             $fields['currentPassword'] = '******';
             $fields['newPassword'] = '******';
             $fields['newPasswordRepeat'] = 'new password repeated';
             $this->validation->set_rules($rules);
             $this->validation->set_fields($fields);
             if ($this->validation->run() === true) {
                 $user = new User();
                 $user->setKey($this->_getUser());
                 $user->retrieve();
                 if ($user->get('password') === $user->makePass($this->input->post('currentPassword'))) {
                     $user->set('password', $user->makePass($this->input->post('newPassword')));
                     $viewData['checkpoints'][] = 'You have successfully changed your password.';
                     $user->update();
                 } else {
                     $viewData['errors'][] = 'You did not enter your current password correctly.';
                 }
             }
         }
     }
     $viewData['token'] = $this->_token();
     $user = new User();
     $script = new Script();
     $user->retrieve($this->session->userdata('email'));
     if ($user->getType() === User::FB_CONNECT) {
         $viewData['email'] = false;
         $viewData['UID'] = $user->getKey();
         $viewData['name'] = $user->name();
         $viewData['institution'] = $user->institution();
         if (!($subject = $user->subject())) {
             $subject = 'Not specified on Facebook';
         }
         $viewData['subject'] = $subject;
         $viewData['fbEmail'] = $user->get('fbEmail');
     } else {
         $viewData['email'] = $user->getKey();
         $viewData['name'] = $user->get('name');
         $user->get('subject') ? $viewData['subject'] = $user->get('subject') : ($viewData['subject'] = 'Not specified');
         $viewData['institution'] = $user->get('institution');
     }
     //$viewData['messages'][] = 'We are on day '.ceil((time() - 1229536800)/86400).' of the Exambuff pilot. Thanks for taking part!';
     $this->_template('user/panel', 'Your account', 'my-account', $viewData);
 }
 /**
  * Sole constructor.
  */
 function SchedulersJob()
 {
     parent::SugarBean();
     require_once 'modules/Users/User.php';
     $user = new User();
     $user->retrieve('1');
     // Scheduler jobs run as Admin
     $this->user = $user;
 }
Example #13
0
 /**
  * Sole constructor.
  */
 function SchedulersJob($init = true)
 {
     parent::SugarBean();
     if ($init) {
         $user = new User();
         $user->retrieve('1');
         // Scheduler jobs run as Admin
         $this->user = $user;
     }
 }
Example #14
0
 public function activate($key)
 {
     if ($this->retrieve($key)) {
         $user = new User();
         if ($user->retrieve($this->get('email'))) {
             $user->activate();
             $this->delete();
             return true;
         }
     }
     return false;
 }
  public function show($id) {
    $this->template->id = $id;

    // get the user with id = $id
    $user = User::retrieve(array('id' => $id));
    if (count($user) == 1) {
      $this->template->user = $user;
    } else if (count($user) == 0) {
      $this->template->id = $id;
    }

    $this->template->display('show.html.php');
  }
 /**
  * Sole constructor.
  */
 function SchedulersJob($init = true)
 {
     parent::SugarBean();
     if ($init) {
         $user = new User();
         //check is default admin exists
         $adminId = $this->db->getOne('SELECT id FROM users WHERE id=1 AND is_admin=1 AND deleted=0 AND status=\'Active\'', true, 'Error retrieving Admin account info');
         if (false === $adminId) {
             //retrive other admin
             $adminId = $this->db->getOne('SELECT id FROM users WHERE is_admin=1 AND deleted=0 AND status=\'Active\'', true, 'Error retrieving Admin account info');
             if ($adminId) {
                 $user->retrieve($adminId);
             } else {
                 $GLOBALS['log']->fatal('No Admin account found!');
                 return false;
             }
         } else {
             $user->retrieve('1');
             // Scheduler jobs run as default Admin
         }
         $this->user = $user;
     }
 }
Example #17
0
 static function setUpBeforeClass()
 {
     global $app_strings, $app_list_strings;
     $app_strings = return_application_language($GLOBALS['current_language']);
     $app_list_strings = return_app_list_strings_language($GLOBALS['current_language']);
     $user = new User();
     $user->retrieve('1');
     $GLOBALS['current_user'] = $user;
     self::$contact = SugarTestContactUtilities::createContact();
     self::$contact->first_name = 'Bug43395';
     self::$contact->last_name = 'Test';
     self::$contact->salutation = 'Mr.';
     self::$contact->save();
 }
Example #18
0
 public function testFormatFieldInSugarFieldRelate()
 {
     global $current_user;
     $current_user = new User();
     $current_user->retrieve('1');
     $current_user->setPreference('default_locale_name_format', 'l f s');
     $sugar_field_relate = new SugarFieldRelate('Relate');
     $new_field = $sugar_field_relate->formatField('Max Liang', array('name' => 'contact_name'));
     $this->assertEquals(trim($new_field), trim('Liang Max'), "Assert that name format is correct");
     $current_user->setPreference('default_locale_name_format', 'f l s');
     $sugar_field_relate = new SugarFieldRelate('Relate');
     $new_field = $sugar_field_relate->formatField('Max Liang', array('name' => 'contact_name'));
     $this->assertEquals(trim($new_field), trim('Max Liang'), "Assert that name format is correct");
 }
 public function authenticateUser($username, $password)
 {
     $user = $this->box->getCurrentUser();
     if (empty($user)) {
         return '';
     }
     $usr = new User();
     $usr_id = $usr->retrieve_user_id($username);
     if (empty($usr_id)) {
         $usr_id = $this->createUser($user);
     }
     $usr->retrieve($usr_id);
     return $usr->id;
 }
Example #20
0
 protected function action_delete()
 {
     if ($_REQUEST['record'] != $GLOBALS['current_user']->id && $GLOBALS['current_user']->isAdminForModule('Users')) {
         $u = new User();
         $u->retrieve($_REQUEST['record']);
         $u->deleted = 1;
         $u->status = 'Inactive';
         $u->employee_status = 'Terminated';
         $u->save();
         $GLOBALS['log']->info("User id: {$GLOBALS['current_user']->id} deleted user record: {$_REQUEST['record']}");
         SugarApplication::redirect("index.php?module=Employees&action=index");
     } else {
         sugar_die("Unauthorized access to administration.");
     }
 }
Example #21
0
 /**
  * Test creates new account and tries to find the account by wildcard of its email
  *
  * @group 41392
  */
 public function testSearchByModule()
 {
     $user = new User();
     $user->retrieve(1);
     $account = new Account();
     $account->name = 'Bug4192Test';
     $account->email1 = '*****@*****.**';
     $account->save();
     $GLOBALS['db']->commit();
     $params = array('user_name' => $user->user_name, 'password' => $user->user_hash, 'search_string' => '*****@*****.**', 'modules' => array('Accounts'), 'offset' => 0, 'max_results' => 30);
     $actual = $this->_soapClient->call('search_by_module', $params);
     $account->mark_deleted($account->id);
     $this->assertGreaterThan(0, $actual['result_count'], 'Call must return one bean minimum');
     $this->assertEquals('Accounts', $actual['entry_list'][0]['module_name'], 'Bean must be account');
     $this->assertEquals($account->id, $actual['entry_list'][0]['id'], 'Bean id must be same as id of created account');
 }
Example #22
0
 function display()
 {
     $smarty = new Sugar_Smarty();
     parent::display();
     $db = DBManagerFactory::getInstance();
     //$myquery = 'SELECT tab4.first_name fname, tab4.last_name lname,  tab5.mrn_c mrn, tab4.id patid, tab5.location_c location, tab5.active_c active, ( SELECT tab1.reg_patient_reg_encounterreg_encounter_idb enclink  FROM reg_patient_reg_encounter_c tab1 WHERE  tab1.reg_patient_reg_encounterreg_patient_ida = patid AND tab1.date_modified = (SELECT max( date_modified ) dat FROM reg_patient_reg_encounter_c enc1 WHERE  enc1.reg_patient_reg_encounterreg_patient_ida = patid) )  enclink, ( SELECT DATE_FORMAT(tab3.next_rx_refill_due_c,"%m/%d/%Y") ref1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  refill,  ( SELECT DATE_FORMAT(tab3.last_uts_c,"%m/%d/%Y") uts1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink ) last_uts , ( SELECT DATE_FORMAT(tab3.next_uts_due_c,"%m/%d/%Y") uts11 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  uts ,  (SELECT DATE_FORMAT(tab3.next_pcp_visit_c,"%m/%d/%Y") pcp11 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  next_pcp,  (SELECT p1b.name provname  from reg_provider p1b, reg_provider_reg_patient_c p2b  WHERE p2b.reg_provider_reg_patientreg_provider_ida = p1b.id  AND p2b.reg_provider_reg_patientreg_patient_idb = patid) provname, ( SELECT risklvl_c risk1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  risk FROM reg_patient tab4, reg_patient_cstm tab5, reg_patient_reg_encounter_c tab1, ( SELECT max( date_modified ) dat, reg_patient_reg_encounterreg_patient_ida pat FROM reg_patient_reg_encounter_c GROUP BY reg_patient_reg_encounterreg_patient_ida) tab2, reg_encounter_cstm tab3 WHERE  tab5.id_c = tab4.id  AND tab1.date_modified = tab2.dat AND tab1.reg_patient_reg_encounterreg_patient_ida = tab2.pat AND tab3.id_c = tab1.reg_patient_reg_encounterreg_encounter_idb  AND tab4.id = tab2.pat';
     $myquery = 'SELECT tab4.first_name fname, tab4.last_name lname,  tab5.mrn_c mrn, tab4.id patid, tab5.location_c location, tab5.active_c active, ( SELECT tab1.reg_patient_reg_encounterreg_encounter_idb enclink  FROM reg_patient_reg_encounter_c tab1 WHERE  tab1.reg_patient_reg_encounterreg_patient_ida = patid AND tab1.date_modified = (SELECT max( date_modified ) dat FROM reg_patient_reg_encounter_c enc1 WHERE  enc1.reg_patient_reg_encounterreg_patient_ida = patid) )  enclink, ( SELECT DATE_FORMAT(tab3.next_rx_refill_due_c,"%m/%d/%Y") ref1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  refill,  ( SELECT DATE_FORMAT(tab3.last_uts_c,"%m/%d/%Y") uts1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink ) last_uts , ( SELECT DATE_FORMAT(tab3.next_uts_due_c,"%m/%d/%Y") uts11 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  uts ,  (SELECT DATE_FORMAT(tab3.next_pcp_visit_c,"%m/%d/%Y") pcp11 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  next_pcp,  (SELECT p1b.name provname  from reg_provider p1b, reg_provider_reg_patient_c p2b  WHERE p2b.reg_provider_reg_patientreg_provider_ida = p1b.id  AND p2b.reg_provider_reg_patientreg_patient_idb = patid) provname, ( SELECT risklvl_c risk1 FROM reg_encounter_cstm tab3 where tab3.id_c = enclink )  risk FROM reg_patient tab4, reg_patient_cstm tab5 WHERE  tab5.id_c = tab4.id ';
     $result = $db->query($myquery);
     $mydata = null;
     while ($row = $db->fetchRow($result)) {
         $mydata[] = $row;
     }
     global $cal_strings, $current_language;
     $cal_strings = return_module_language($current_language, 'Calendar');
     if (empty($_REQUEST['view'])) {
         $_REQUEST['view'] = SugarConfig::getInstance()->get('calendar.default_view', 'week');
     }
     $cal = new Calendar($_REQUEST['view']);
     if (in_array($cal->view, array('day', 'week', 'month'))) {
         $cal->add_activities($GLOBALS['current_user']);
     } else {
         if ($cal->view == 'shared') {
             $cal->init_shared();
             global $shared_user;
             $shared_user = new User();
             foreach ($cal->shared_ids as $member) {
                 $shared_user->retrieve($member);
                 $cal->add_activities($shared_user);
             }
         }
     }
     if (in_array($cal->view, array("day", "week", "month", "shared"))) {
         $cal->load_activities();
     }
     if (!empty($_REQUEST['print']) && $_REQUEST['print'] == 'true') {
         $cal->setPrint(true);
     }
     $display = new CalendarDisplay($cal);
     $smarty->assign("mydata", $mydata);
     echo "<table><tr><td>";
     $smarty->display($this->lv->tpl);
     echo "</td>";
     echo "<td style='width:100%;vertical-align:top'>";
     $caltest = new caltest();
     $caltest->test();
     echo "</td></tr></table>";
 }
Example #23
0
function _edit($uid = 0)
{
    require_login();
    $user = new User();
    $user->retrieve($uid);
    if (!$user->exists()) {
        $data['body'][] = '<p>User Not Found!</p>';
    } else {
        $fdata['form_heading'] = 'Edit User';
        $fdata['user'] = $user;
        $form = View::do_fetch(VIEW_PATH . 'users/edit.php', $fdata);
        $data['head'][] = View::do_fetch(VIEW_PATH . 'users/edit_js.php');
        $data['body'][] = '<h2>Edit User</h2>';
        $data['body'][] = $form;
    }
    View::do_dump(VIEW_PATH . 'layouts/mainlayout.php', $data);
}
Example #24
0
 protected function action_delete()
 {
     if ($_REQUEST['record'] != $GLOBALS['current_user']->id && $GLOBALS['current_user']->isAdminForModule('Users')) {
         $u = new User();
         $u->retrieve($_REQUEST['record']);
         $u->status = 'Inactive';
         $u->employee_status = 'Terminated';
         $u->save();
         $u->mark_deleted($u->id);
         $GLOBALS['log']->info("User id: {$GLOBALS['current_user']->id} deleted user record: {$_REQUEST['record']}");
         $eapm = loadBean('EAPM');
         $eapm->delete_user_accounts($_REQUEST['record']);
         $GLOBALS['log']->info("Removing user's External Accounts");
         SugarApplication::redirect("index.php?module=Users&action=index");
     } else {
         sugar_die("Unauthorized access to administration.");
     }
 }
Example #25
0
 public function setUp()
 {
     global $sugar_config;
     $this->save_query = isset($sugar_config['save_query']) ? true : false;
     $this->current_language = $GLOBALS['current_language'];
     global $current_user;
     $current_user = new User();
     $current_user->retrieve('1');
     global $mod_strings, $app_strings;
     $mod_strings = return_module_language('en_us', 'Accounts');
     $app_strings = return_application_language('en_us');
     $beanList = array();
     $beanFiles = array();
     require 'include/modules.php';
     $GLOBALS['beanList'] = $beanList;
     $GLOBALS['beanFiles'] = $beanFiles;
     require 'sugar_version.php';
     $GLOBALS['sugar_version'] = $sugar_version;
 }
function _ops_update()
{
    loginRequireMgmt();
    if (!loginCheckPermission(USER::MGMT_USER)) {
        redirect("errors/401");
    }
    $msg = '';
    $OID = max(0, intval($_POST['OID']));
    $CID = max(0, intval($_POST['CID']));
    if ($_POST['password'] != $_POST['confirm']) {
        redirect("mgmt_user/edit", "password not equal to confirm");
    }
    $object = new User();
    if ($OID) {
        $object->retrieve($OID, $CID);
        $object->merge($_POST);
        if ($_POST['password'] != "") {
            $object->setPassword($_POST['password']);
        }
        if (!$object->exists()) {
            $msg = 'User not found!';
        } else {
            if ($object->update()) {
                $msg = 'User updated!';
            } else {
                $msg = 'User update failed!';
            }
        }
    } else {
        $object->merge($_POST);
        if ($_POST['password'] != "") {
            $object->setPassword($_POST['password']);
        }
        if ($object->create()) {
            $msg = 'User inserted!';
        } else {
            $msg = 'User insert failed!';
        }
    }
    redirect('mgmt_user/manage', $msg);
}
Example #27
0
 /**
  * Ensure that a new instance of EmailAddress is created during creating
  * User duplicate
  */
 public function testCreateDuplicate()
 {
     // retrieve created user from database in order to populate email addresses
     $original = new User();
     $original->retrieve($this->user->id);
     // simulate request parameters of "Duplicate" web form
     $address = $original->emailAddress->addresses[0];
     $_REQUEST = array('Users_email_widget_id' => '1', 'Users1emailAddress0' => $address['email_address'], 'Users1emailAddressId0' => $address['email_address_id']);
     // create a duplicate and retrieve it from database as well
     $duplicate = $this->duplicate = new User();
     $duplicate->save();
     $retrieved = new User();
     $retrieved->retrieve($duplicate->id);
     // ensure that email address is created in duplicate
     $this->assertEquals(1, count($retrieved->emailAddress->addresses));
     // ensure that it's value is the same as original email address
     $this->assertEquals($original->emailAddress->addresses[0]['email_address'], $retrieved->emailAddress->addresses[0]['email_address']);
     // ensure that new instance of EmailAddress is created instead of
     // sharing the same instance between users
     $this->assertNotEquals($original->emailAddress->addresses[0]['email_address_id'], $retrieved->emailAddress->addresses[0]['email_address_id']);
 }
Example #28
0
 static function eventSave($bean)
 {
     if (!self::init()) {
         return false;
     }
     $userids = array();
     $userids[] = $bean->assigned_user_id;
     if (!empty($bean->users_arr) && is_array($bean->users_arr)) {
         foreach ($bean->users_arr as $id) {
             $userids[] = $id;
         }
     }
     $userids = array_unique($userids);
     foreach ($userids as $id) {
         $user = new User();
         $user->retrieve($id);
         if (!empty($user->googleaccount_c) && !empty($user->googlepass_c)) {
             self::checkEvent($bean, $user);
         }
     }
 }
Example #29
0
function updateUIState($ui_state, $call_record, $asterisk_id)
{
    $cUser = new User();
    $cUser->retrieve($_SESSION['authenticated_user_id']);
    // query log
    // Very basic santization
    $uiState = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $ui_state);
    // mysql_real_escape_string($_REQUEST['ui_state']);
    $callRecord = preg_replace('/[^a-z0-9\\-\\. ]/i', '', $call_record);
    //mysql_real_escape_string($_REQUEST['call_record']);
    $asteriskID = preg_replace('/-/', '.', $asterisk_id);
    // Workaround See Discussion here: https://github.com/blak3r/yaai/pull/20
    if (isset($call_record)) {
        $query = "update asterisk_log set uistate=\"{$uiState}\" where call_record_id=\"{$callRecord}\"";
    } else {
        $query = "update asterisk_log set uistate=\"{$uiState}\" where asterisk_id=\"{$asteriskID}\"";
    }
    $cUser->db->query($query, false);
    if ($cUser->db->checkError()) {
        trigger_error("Update UIState-Query failed: {$query}");
    }
}
Example #30
0
 function display()
 {
     $users_arr = array();
     require_once "modules/Users/User.php";
     $user_ids = explode(",", trim($_REQUEST['users'], ','));
     $user_ids = array_unique($user_ids);
     require_once 'include/json_config.php';
     global $json;
     $json = getJSONobj();
     $json_config = new json_config();
     foreach ($user_ids as $u_id) {
         if (empty($u_id)) {
             continue;
         }
         $bean = new User();
         $bean->retrieve($u_id);
         array_push($users_arr, $json_config->populateBean($bean));
     }
     $GRjavascript = "\n" . $json_config->global_registry_var_name . "['focus'].users_arr = " . $json->encode($users_arr) . ";\n";
     ob_clean();
     echo $GRjavascript;
 }