Пример #1
0
 function action_marker_detail_map()
 {
     $this->view = 'marker_detail_map';
     $jjwg_Markers = get_module_info('jjwg_Markers');
     // Get the map object
     if (is_guid($_REQUEST['id'])) {
         $jjwg_Markers->retrieve($_REQUEST['id']);
     }
     $GLOBALS['loc'] = $jjwg_Markers->define_loc();
 }
Пример #2
0
 function action_area_detail_map()
 {
     $this->view = 'area_detail_map';
     $jjwg_Areas = get_module_info('jjwg_Areas');
     // Get the map object
     if (is_guid($_REQUEST['id'])) {
         $jjwg_Areas->retrieve($_REQUEST['id']);
     }
     $GLOBALS['polygon'] = $jjwg_Areas->define_polygon();
     $GLOBALS['loc'] = $jjwg_Areas->define_area_loc();
 }
Пример #3
0
 /**
  * action map_markers
  * Google Maps - Output the Map Markers
  */
 function action_map_markers()
 {
     header_remove('X-Frame-Options');
     $this->view = 'map_markers';
     // Define globals for use in the view.
     $this->bean->map_center = array();
     $this->bean->map_markers = array();
     $this->bean->map_markers_groups = array();
     $this->bean->custom_markers = array();
     $this->bean->custom_areas = array();
     // Create New Sugar_Smarty Object
     $this->sugarSmarty = new Sugar_Smarty();
     $this->sugarSmarty->assign("mod_strings", $GLOBALS['mod_strings']);
     $this->sugarSmarty->assign("app_strings", $GLOBALS['app_strings']);
     $this->sugarSmarty->assign('app_list_strings', $GLOBALS['app_list_strings']);
     $this->sugarSmarty->assign('moduleListSingular', $GLOBALS['app_list_strings']['moduleListSingular']);
     $this->sugarSmarty->assign('moduleList', $GLOBALS['app_list_strings']['moduleList']);
     //echo '<pre>';
     //var_dump($_REQUEST);
     // Related Map Record Defines the Map
     if (!empty($_REQUEST['record']) || !empty($_REQUEST['relate_id']) && !empty($_REQUEST['relate_module']) || !empty($_REQUEST['quick_address']) && !empty($_REQUEST['display_module'])) {
         // If map 'record' then define map details from current module.
         if (@is_guid($_REQUEST['record'])) {
             // Get the map object
             $map = get_module_info($GLOBALS['currentModule']);
             $map->retrieve($_REQUEST['record']);
             // Define map variables
             $map_parent_type = $map->parent_type;
             $map_parent_id = $map->parent_id;
             $map_module_type = $map->module_type;
             $map_unit_type = $map->unit_type;
             $map_distance = $map->distance;
         } else {
             if (@(is_guid($_REQUEST['relate_id']) && !empty($_REQUEST['relate_module']))) {
                 // Define map variables
                 $map_parent_type = $_REQUEST['relate_module'];
                 $map_parent_id = $_REQUEST['relate_id'];
                 $map_module_type = !empty($_REQUEST['display_module']) ? $_REQUEST['display_module'] : $_REQUEST['relate_module'];
                 $map_distance = !empty($_REQUEST['distance']) ? $_REQUEST['distance'] : $this->settings['map_default_distance'];
                 $map_unit_type = !empty($_REQUEST['unit_type']) ? $_REQUEST['unit_type'] : $this->settings['map_default_unit_type'];
             } else {
                 if (!empty($_REQUEST['quick_address']) && !empty($_REQUEST['display_module'])) {
                     // Define map variables / No Parent
                     $map_parent_type = null;
                     $map_parent_id = null;
                     $map_module_type = !empty($_REQUEST['display_module']) ? $_REQUEST['display_module'] : $_REQUEST['relate_module'];
                     $map_distance = !empty($_REQUEST['distance']) ? $_REQUEST['distance'] : $this->settings['map_default_distance'];
                     $map_unit_type = !empty($_REQUEST['unit_type']) ? $_REQUEST['unit_type'] : $this->settings['map_default_unit_type'];
                 }
             }
         }
         // Define display object, note - 'Accounts_Members' is a special display type
         $this->display_object = $map_module_type == 'Accounts_Members' ? get_module_info('Accounts') : get_module_info($map_module_type);
         $mod_strings_display = return_module_language($GLOBALS['current_language'], $this->display_object->module_name);
         $mod_strings_display = array_merge($mod_strings_display, $GLOBALS['mod_strings']);
         // If relate module/id object
         if (!empty($map_parent_type) && !empty($map_parent_id)) {
             // Define relate objects
             $this->relate_object = get_module_info($map_parent_type);
             $this->relate_object->retrieve($map_parent_id);
             $mod_strings_related = return_module_language($GLOBALS['current_language'], $this->relate_object->module_name);
             $mod_strings_related = array_merge($mod_strings_related, $GLOBALS['mod_strings']);
             // Get the Relate object Assoc Data
             $where_conds = $this->relate_object->table_name . ".id = '" . $map_parent_id . "'";
             $query = $this->relate_object->create_new_list_query("" . $this->relate_object->table_name . ".assigned_user_id", $where_conds, array(), array(), 0, '', false, $this->relate_object, false);
             //var_dump($query);
             $relate_result = $this->bean->db->query($query);
             $relate = $this->bean->db->fetchByAssoc($relate_result);
             // Add Relate (Center Point) Marker
             $this->bean->map_center = $this->getMarkerData($map_parent_type, $relate, true, $mod_strings_related);
             // Define Center Point
             $center_lat = $this->relate_object->jjwg_maps_lat_c;
             $center_lng = $this->relate_object->jjwg_maps_lng_c;
         } else {
             // Geocode 'quick_address'
             $aInfo = $this->bean->getGoogleMapsGeocode($_REQUEST['quick_address'], false, true);
             // If not status 'OK', then fail here and exit. Note: Inside of iFrame
             if (!empty($aInfo['status']) && $aInfo['status'] != 'OK' && preg_match('/[A-Z\\_]/', $aInfo['status'])) {
                 echo '<br /><br /><div><b>' . $GLOBALS['mod_strings']['LBL_MAP_LAST_STATUS'] . ': ' . $aInfo['status'] . '</b></div><br /><br />';
                 exit;
             }
             //var_dump($aInfo);
             // Define Marker Data
             $aInfo['name'] = $_REQUEST['quick_address'];
             $aInfo['id'] = 0;
             $aInfo['module'] = $map_module_type == 'Accounts_Members' ? 'Accounts' : $map_module_type;
             $aInfo['address'] = $_REQUEST['quick_address'];
             $aInfo['jjwg_maps_address_c'] = $_REQUEST['quick_address'];
             $aInfo['jjwg_maps_lat_c'] = $aInfo['lat'];
             $aInfo['jjwg_maps_lng_c'] = $aInfo['lng'];
             $this->bean->map_center = $this->getMarkerData($map_parent_type, $aInfo, true);
             // Define Center Point
             $center_lat = $aInfo['lat'];
             $center_lng = $aInfo['lng'];
         }
         //var_dump($aInfo);
         // Define $x and $y expressions
         $x = '(69.1*((' . $this->display_object->table_name . '_cstm.jjwg_maps_lat_c)-(' . $center_lat . ')))';
         $y = '(53.0*((' . $this->display_object->table_name . '_cstm.jjwg_maps_lng_c)-(' . $center_lng . ')) * COS((' . $center_lat . ')/57.1))';
         $calc_distance_expression = 'SQRT(' . $x . '*' . $x . '+' . $y . '*' . $y . ')';
         if (strtolower($map_unit_type) == 'km' || strtolower($map_unit_type) == 'kilometer') {
             $calc_distance_expression .= '*1.609';
             // 1 mile = 1.609 km
         }
         // Find the Items to Display
         // Assume there is no address at 0,0; it's in the Atlantic Ocean!
         $where_conds = "(" . $this->display_object->table_name . "_cstm.jjwg_maps_lat_c != 0 OR " . "" . $this->display_object->table_name . "_cstm.jjwg_maps_lng_c != 0) " . " AND " . "(" . $this->display_object->table_name . "_cstm.jjwg_maps_geocode_status_c = 'OK')" . " AND " . "(" . $calc_distance_expression . " < " . $map_distance . ")";
         $query = $this->display_object->create_new_list_query('display_object_distance', $where_conds, array(), array(), 0, '', false, $this->display_object, false);
         // Add the disply_object_distance into SELECT list
         $query = str_replace('SELECT ', 'SELECT (' . $calc_distance_expression . ') AS display_object_distance, ', $query);
         if ($map_module_type == 'Contacts') {
             // Contacts - Account Name
             $query = str_replace(' FROM contacts ', ' ,accounts.name AS account_name, accounts.id AS account_id  FROM contacts  ', $query);
             $query = str_replace(' FROM contacts ', ' FROM contacts LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id and accounts_contacts.deleted = 0 LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id AND accounts.deleted=0 ', $query);
         } elseif ($map_module_type == 'Opportunities') {
             // Opps - Account Name
             $query = str_replace(' FROM opportunities ', ' ,accounts.name AS account_name, accounts.id AS account_id  FROM opportunities  ', $query);
             $query = str_replace(' FROM opportunities ', ' FROM opportunities LEFT JOIN accounts_opportunities ON opportunities.id=accounts_opportunities.opportunity_id and accounts_opportunities.deleted = 0 LEFT JOIN accounts ON accounts_opportunities.account_id=accounts.id AND accounts.deleted=0 ', $query);
         } elseif ($map_module_type == 'Accounts_Members') {
             // 'Accounts_Members' is a special display type
             $query = str_replace(' AND accounts.deleted=0', ' AND accounts.deleted=0 AND accounts.parent_id = \'' . $this->bean->db->quote($map_parent_id) . '\'', $query);
         }
         //var_dump($query);
         $display_result = $this->bean->db->limitQuery($query, 0, $this->settings['map_markers_limit']);
         while ($display = $this->bean->db->fetchByAssoc($display_result)) {
             if (!empty($map_distance) && !empty($display['id'])) {
                 $marker_data_module_type = $map_module_type == 'Accounts_Members' ? 'Accounts' : $map_module_type;
                 $marker_data = $this->getMarkerData($marker_data_module_type, $display, false, $mod_strings_display);
                 if (!empty($marker_data)) {
                     $this->bean->map_markers[] = $marker_data;
                 }
             }
         }
         //var_dump($this->bean->map_markers);
         // Next define the Custom Markers and Areas related to this Map
         // Define relate and display objects from the necessary classes (utils.php)
         @($markers_object = get_module_info('jjwg_Markers'));
         @($areas_object = get_module_info('jjwg_Areas'));
         // Relationship Names: jjwg_maps_jjwg_areas and jjwg_maps_jjwg_markers
         // Find the Related Beans: Maps to Markers
         if (@(is_object($markers_object) && is_object($map))) {
             $related_custom_markers = $map->get_linked_beans('jjwg_maps_jjwg_markers', 'jjwg_Markers');
             if ($related_custom_markers) {
                 foreach ($related_custom_markers as $marker_bean) {
                     $marker_data = $this->getMarkerDataCustom($marker_bean);
                     if (!empty($marker_data)) {
                         $this->bean->custom_markers[] = $marker_data;
                     }
                 }
             }
         }
         // Find the Related Beans: Maps to Areas
         if (@(is_object($areas_object) && is_object($map))) {
             $related_custom_areas = $map->get_linked_beans('jjwg_maps_jjwg_areas', 'jjwg_Areas');
             if ($related_custom_areas) {
                 foreach ($related_custom_areas as $area_bean) {
                     $area_data = $this->getAreaDataCustom($area_bean);
                     if (!empty($area_data)) {
                         $this->bean->custom_areas[] = $area_data;
                     }
                 }
             }
         }
         // Map Target List (ProspectLists)
     } elseif (!empty($_REQUEST['list_id'])) {
         $this->bean->map_markers = array();
         $this->display_object = get_module_info('ProspectLists');
         // Use the Export Query
         if (!empty($_REQUEST['list_id'])) {
             $this->display_object->retrieve($_REQUEST['list_id']);
             if ($this->display_object->id == $_REQUEST['list_id']) {
                 $prospect_list_object = $this->display_object;
                 $list_id = $this->display_object->id;
             }
         }
         if (!empty($list_id)) {
             $list_modules = array('Accounts', 'Contacts', 'Leads', 'Users', 'Prospects');
             $temp_marker_groups = array();
             foreach ($list_modules as $display_module) {
                 $this->display_object = get_module_info($display_module);
                 $mod_strings_display = return_module_language($GLOBALS['current_language'], $this->display_object->module_name);
                 $mod_strings_display = array_merge($mod_strings_display, $GLOBALS['mod_strings']);
                 // Find the Items to Display
                 // Assume there is no address at 0,0; it's in the Atlantic Ocean!
                 $where_conds = "(" . $this->display_object->table_name . "_cstm.jjwg_maps_lat_c != 0 OR " . "" . $this->display_object->table_name . "_cstm.jjwg_maps_lng_c != 0) " . " AND " . "(" . $this->display_object->table_name . "_cstm.jjwg_maps_geocode_status_c = 'OK')";
                 $query = $this->display_object->create_new_list_query('', $where_conds, array(), array(), 0, '', false, $this->display_object, false);
                 if ($display_module == 'Contacts') {
                     // Contacts - Account Name
                     $query = str_replace(' FROM contacts ', ' ,accounts.name AS account_name, accounts.id AS account_id  FROM contacts  ', $query);
                     $query = str_replace(' FROM contacts ', ' FROM contacts LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id and accounts_contacts.deleted = 0 LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id AND accounts.deleted=0 ', $query);
                 }
                 // Add List JOIN
                 $query = str_replace(' FROM ' . $this->display_object->table_name . ' ', ' FROM ' . $this->display_object->table_name . ' ' . 'LEFT JOIN prospect_lists_prospects ON prospect_lists_prospects.related_id = ' . $this->display_object->table_name . '.id AND prospect_lists_prospects.deleted=0 ' . 'LEFT JOIN prospect_lists ON prospect_lists_prospects.prospect_list_id = prospect_lists.id AND prospect_lists.deleted=0 ', $query);
                 // Restrict WHERE to related type and $list_id
                 $query .= ' AND prospect_lists_prospects.related_type = \'' . $this->display_object->module_name . '\' AND ' . 'prospect_lists.id = \'' . $this->bean->db->quote($list_id) . '\'';
                 //var_dump($query);
                 $display_result = $this->bean->db->limitQuery($query, 0, $this->settings['map_markers_limit']);
                 $display_type_found = false;
                 while ($display = $this->bean->db->fetchByAssoc($display_result)) {
                     if (!empty($display['id'])) {
                         $marker_data = $this->getMarkerData($display_module, $display, false, $mod_strings_display);
                         $marker_data['group'] = $GLOBALS['app_list_strings']['moduleList'][$display_module];
                         if (!empty($marker_data)) {
                             $this->bean->map_markers[] = $marker_data;
                         }
                         $display_type_found = true;
                     }
                 }
                 if ($display_type_found) {
                     $temp_marker_groups[] = $GLOBALS['app_list_strings']['moduleList'][$display_module];
                 }
             }
             $this->bean->map_markers_groups = $temp_marker_groups;
         }
         // Map Records
     } elseif (!empty($_REQUEST['uid']) || !empty($_REQUEST['current_post'])) {
         if (in_array($_REQUEST['display_module'], $this->settings['valid_geocode_modules'])) {
             $display_module = $_REQUEST['display_module'];
         } else {
             $display_module = 'Accounts';
         }
         if ($_REQUEST['current_post'] == 'session') {
             $current_post = $_SESSION['jjwg_Maps']['current_post'];
         } else {
             $current_post = $_REQUEST['current_post'];
         }
         $query = '';
         $selected_query = '';
         $records = array();
         $order_by = '';
         $this->display_object = get_module_info($display_module);
         $mod_strings_display = return_module_language($GLOBALS['current_language'], $this->display_object->module_name);
         $mod_strings_display = array_merge($mod_strings_display, $GLOBALS['mod_strings']);
         if (!empty($_REQUEST['uid'])) {
             // Several records selected or this page
             $records = explode(',', $_REQUEST['uid']);
         } elseif (!empty($current_post)) {
             // Select all records (advanced search)
             $search_array = generateSearchWhere($display_module, $current_post);
             //var_dump($search_array);
             if (!empty($search_array['where'])) {
                 // Related Field Bug: Get relate/link patched 'where' and 'join'
                 @($ret_array = create_export_query_relate_link_patch($display_module, $search_array['searchFields'], $search_array['where']));
                 if (!empty($ret_array['join'])) {
                     @($selected_query = $this->display_object->create_export_query($order_by, $ret_array['where'], $ret_array['join']));
                 } else {
                     @($selected_query = $this->display_object->create_export_query($order_by, $ret_array['where']));
                 }
                 // SugarOnDemand JOIN Bug: If $ret_array['join'] is not included in query, force it in!
                 if (strpos($ret_array['join'], $selected_query) === false) {
                     $selected_query = str_replace(' where ', $ret_array['join'] . ' where ', $selected_query);
                 }
                 // Avoiding subquery. Let's just record the record ID's for later
                 $selected_result = $this->bean->db->limitQuery($selected_query, 0, $this->settings['map_markers_limit']);
                 while ($display = $this->bean->db->fetchByAssoc($selected_result)) {
                     $records[] = $display['id'];
                 }
             }
         }
         //var_dump($records);
         // Find the Items to Display
         // Assume there is no address at 0,0; it's in the Atlantic Ocean!
         $where_conds = "(" . $this->display_object->table_name . "_cstm.jjwg_maps_lat_c != 0 OR " . "" . $this->display_object->table_name . "_cstm.jjwg_maps_lng_c != 0) " . " AND " . "(" . $this->display_object->table_name . "_cstm.jjwg_maps_geocode_status_c = 'OK')";
         $query = $this->display_object->create_new_list_query('', $where_conds, array(), array(), 0, '', false, $this->display_object, false);
         if ($display_module == 'Contacts') {
             // Contacts - Account Name
             $query = str_replace(' FROM contacts ', ' ,accounts.name AS account_name, accounts.id AS account_id  FROM contacts  ', $query);
             $query = str_replace(' FROM contacts ', ' FROM contacts LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id and accounts_contacts.deleted = 0 LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id AND accounts.deleted=0 ', $query);
         } elseif ($display_module == 'Opportunities') {
             // Opps - Account Name
             $query = str_replace(' FROM opportunities ', ' ,accounts.name AS account_name, accounts.id AS account_id  FROM opportunities  ', $query);
             $query = str_replace(' FROM opportunities ', ' FROM opportunities LEFT JOIN accounts_opportunities ON opportunities.id=accounts_opportunities.opportunity_id and accounts_opportunities.deleted = 0 LEFT JOIN accounts ON accounts_opportunities.account_id=accounts.id AND accounts.deleted=0 ', $query);
         }
         //var_dump($query);
         $display_result = $this->bean->db->limitQuery($query, 0, $this->settings['map_markers_limit']);
         $this->bean->map_markers = array();
         while ($display = $this->bean->db->fetchByAssoc($display_result)) {
             if (!empty($search_array['where'])) {
                 // Select all records (advanced search) with where clause
                 if (in_array($display['id'], $records)) {
                     $this->bean->map_markers[] = $this->getMarkerData($display_module, $display, false, $mod_strings_display);
                 }
             } elseif (!empty($_REQUEST['uid'])) {
                 // Several records selected or this page selected
                 if (in_array($display['id'], $records)) {
                     $this->bean->map_markers[] = $this->getMarkerData($display_module, $display, false, $mod_strings_display);
                 }
             } else {
                 // All
                 $this->bean->map_markers[] = $this->getMarkerData($display_module, $display, false, $mod_strings_display);
             }
         }
     }
     // Sort marker groups for the view
     sort($this->bean->map_markers_groups);
     // Set display object for later use
     $this->bean->display_object = $this->display_object;
     // Get Prospect List Array Dropdown
     $list = get_module_info('ProspectLists');
     $list_query = $list->create_list_query('prospect_lists.name', '1=1', 0);
     $list_result = $list->db->query($list_query);
     $list_array = array();
     while ($alist = $list->db->fetchByAssoc($list_result)) {
         if (!empty($alist['name']) && !empty($alist['id'])) {
             $list_array[$alist['id']] = $alist['name'];
         }
     }
     $this->bean->list_array = $list_array;
 }
Пример #4
0
    if (!$bean instanceof SugarBean) {
        continue;
    }
    if (!$bean->haveFiles()) {
        continue;
    }
    $validBeans[] = $bean;
}
echo '<pre>';
$directory = new DirectoryIterator('upload://');
$stat = array('total' => 0, 'removed' => 0);
foreach ($directory as $node) {
    if (!$node->isFile()) {
        continue;
    }
    if (!is_guid($node->getFilename())) {
        continue;
    }
    $stat['total']++;
    $row = false;
    foreach ($validBeans as $bean) {
        $filter = array('deleted');
        $where = array();
        foreach ($bean->getFilesFields() as $fieldName) {
            $where[] = $fieldName . '=' . $db->quoted($node->getFilename());
            $filter[] = $fieldName;
        }
        $where = '(' . implode(' OR ', $where) . ')';
        $row = $db->fetchOne($bean->create_new_list_query('', $where, $filter, array(), 0));
        if (!empty($row)) {
            break;
Пример #5
0
     if (isset($_REQUEST['ieId']) && isset($_REQUEST['oldFolderName']) && !empty($_REQUEST['oldFolderName']) && isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
         $ie->retrieve($_REQUEST['ieId']);
         $ie->renameFolder($_REQUEST['oldFolderName'], $_REQUEST['newFolderName']);
     } elseif (isset($_REQUEST['folderId']) && !empty($_REQUEST['folderId']) && isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
         if (is_guid($_REQUEST['folderId'])) {
             $email->et->folder->retrieve($_REQUEST['folderId']);
             $email->et->folder->name = $_REQUEST['newFolderName'];
             $email->et->folder->save();
         } else {
             echo "NOOP - not a Sugar Folder";
         }
     }
 case "moveFolder":
     $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: moveFolder");
     if (isset($_REQUEST['folderId']) && !empty($_REQUEST['folderId']) && isset($_REQUEST['newParentId']) && !empty($_REQUEST['newParentId']) && $_REQUEST['newParentId'] != $_REQUEST['folderId']) {
         if (is_guid($_REQUEST['folderId']) && is_guid($_REQUEST['newParentId'])) {
             $email->et->folder->retrieve($_REQUEST['folderId']);
             $email->et->folder->updateFolder(array("record" => $_REQUEST['folderId'], "name" => $email->et->folder->name, "parent_folder" => $_REQUEST['newParentId'], "team_id" => $email->et->folder->team_id, "team_set_id" => $email->et->folder->team_set_id));
         } else {
             echo "NOOP - not a Sugar Folder";
         }
     }
     break;
 case "getGroupFolder":
     $email->et->folder->retrieve($_REQUEST['folderId']);
     $_REQUEST['record'] = $_REQUEST['folderId'];
     $ret = array();
     $ret['folderId'] = $email->et->folder->id;
     $ret['folderName'] = $email->et->folder->name;
     $ret['parentFolderId'] = $email->et->folder->parent_folder;
     $out = $json->encode($ret);
Пример #6
0
 /**
  * @dataProvider providerIsGuid
  */
 public function testIsGuid($guid, $expectedResult)
 {
     $this->assertEquals($expectedResult, is_guid($guid));
 }
Пример #7
0
 /**
  * Retrieve a user's quota using the rollup value, if available.  This method is useful for
  * fetching user quota data when you're unsure about whether or not the given user is a manager.
  * If you would like to force a direct quota, pass a false value to $should_rollup.
  *
  * @param $timeperiod_id String id of the TimePeriod to retrieve quota for
  * @param $user_id String value of the user id to retrieve.  If NULL, the $current_user is used
  * @param $should_rollup boolean value indicating whether or not the quota should be a rollup calculation; false by default
  *
  * @return array [currency_id => int, amount => number, formatted_amount => String]
  */
 public function getRollupQuota($timeperiod_id, $user_id = null, $should_rollup = false)
 {
     if (is_null($user_id)) {
         global $current_user;
         $user_id = $current_user->id;
     }
     // figure out the timeperiod
     // if we didn't find a time period, set the time period to be the current time period
     if (!is_guid($timeperiod_id) && is_numeric($timeperiod_id) && $timeperiod_id != 0) {
         // we have a timestamp, find timeperiod it belongs in
         $timeperiod_id = TimePeriod::getIdFromTimestamp($timeperiod_id);
     }
     if (!is_guid($timeperiod_id)) {
         $timeperiod_id = TimePeriod::getCurrentId();
     }
     $sq = new SugarQuery();
     $sq->select(array('quotas.currency_id', 'quotas.amount'));
     $sq->from(BeanFactory::getBean('Quotas'));
     $sq->where()->equals('user_id', $user_id)->equals('quota_type', $should_rollup ? 'Rollup' : 'Direct')->equals('timeperiod_id', $timeperiod_id);
     $sq->orderBy('date_modified', 'DESC');
     $sq->limit(1);
     // since there is only ever one row, just shift the value off the results
     $row = array_shift($sq->execute());
     if (empty($row)) {
         // This is to prevent return value of false when a given timeperiod has no quota.
         $row = array('currency_id' => -99, 'amount' => 0);
     }
     $row['formatted_amount'] = SugarCurrency::formatAmountUserLocale($row['amount'], $row['currency_id']);
     return $row;
 }
Пример #8
0
 /**
  * Get $db result of records (addresses) in need of geocoding
  * @param $table_name string
  * @param $limit integer
  * @param $id string
  */
 function getGeocodeAddressesResult($table_name, $limit = 0, $id = '')
 {
     if (!in_array($table_name, $this->settings['valid_geocode_tables'])) {
         return false;
     }
     if (empty($limit) || !is_int($limit)) {
         $limit = $this->settings['geocoding_limit'];
     }
     // Find the Items to Geocode
     // Assume there is no address at 0,0; it's in the Atlantic Ocean
     $where_conds = "(" . "(" . $table_name . "_cstm.jjwg_maps_lat_c = 0 AND " . "" . $table_name . "_cstm.jjwg_maps_lng_c = 0)" . " OR " . "(" . $table_name . "_cstm.jjwg_maps_lat_c IS NULL AND " . "" . $table_name . "_cstm.jjwg_maps_lng_c IS NULL)" . ")" . " AND " . "(" . $table_name . "_cstm.jjwg_maps_geocode_status_c = '' OR " . "" . $table_name . "_cstm.jjwg_maps_geocode_status_c IS NULL)";
     // Limit to only one result
     if (@is_guid($id)) {
         $where_conds .= " AND id = '" . $id . "'";
     }
     // Create Simple Query
     // Note: Do not use create_new_list_query() or process_list_query()
     // as they will typically exceeded memory allowed.
     $query = "SELECT " . $table_name . ".*, " . $table_name . "_cstm.* FROM " . $table_name . " LEFT JOIN " . $table_name . "_cstm " . " ON " . $table_name . ".id = " . $table_name . "_cstm.id_c " . " WHERE " . $table_name . ".deleted = 0 AND " . $where_conds;
     $display_result = $this->db->limitQuery($query, 0, $limit);
     return $display_result;
 }
Пример #9
0
 /**
  * @return TimePeriod
  */
 public function getTimeperiod()
 {
     $config = $this->getForecastConfig();
     $type = $config['timeperiod_leaf_interval'];
     $id = $this->getArg('timeperiod_id');
     if (!is_guid($id) && is_numeric($id)) {
         $id = TimePeriod::getIdFromTimestamp($id, $type);
     }
     return TimePeriod::getByType($type, $id);
 }
                 break;
         }
     } else {
         $return['status'] = false;
         $return['errorMessage'] = "NOOP: no folderType defined";
     }
     $out = $json->encode($return);
     echo $out;
     break;
 case "renameFolder":
     $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: renameFolder");
     if (isset($_REQUEST['ieId']) && isset($_REQUEST['oldFolderName']) && !empty($_REQUEST['oldFolderName']) && isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
         $ie->retrieve($_REQUEST['ieId']);
         $ie->renameFolder($_REQUEST['oldFolderName'], $_REQUEST['newFolderName']);
     } elseif (isset($_REQUEST['folderId']) && !empty($_REQUEST['folderId']) && isset($_REQUEST['newFolderName']) && !empty($_REQUEST['newFolderName'])) {
         if (is_guid($_REQUEST['folderId'])) {
             $email->et->folder->retrieve($_REQUEST['folderId']);
             $email->et->folder->name = $_REQUEST['newFolderName'];
             $email->et->folder->save();
         } else {
             echo "NOOP - not a Sugar Folder";
         }
     }
     break;
 case "getGroupFolder":
     $email->et->folder->retrieve($_REQUEST['folderId']);
     $ret = array();
     $ret['folderId'] = $email->et->folder->id;
     $ret['folderName'] = $email->et->folder->name;
     $ret['parentFolderId'] = $email->et->folder->parent_folder;
     $out = $json->encode($ret);
 /**
  * Roll up the data from the rep-worksheets to the manager worksheets
  *
  * @param User $reportee
  * @param $data
  * @return boolean
  */
 public function reporteeForecastRollUp(User $reportee, $data)
 {
     /* @var $quotaSeed Quota */
     $quotaSeed = BeanFactory::getBean('Quotas');
     if (!isset($data['timeperiod_id']) || !is_guid($data['timeperiod_id'])) {
         $data['timeperiod_id'] = TimePeriod::getCurrentId();
     }
     // handle top level managers
     $reports_to = $reportee->reports_to_id;
     if (empty($reports_to)) {
         $reports_to = $reportee->id;
     }
     if (isset($data['forecast_type'])) {
         // check forecast type to see if the assigned_user_id should be equal to the $reportee as it's their own
         // rep worksheet
         if ($data['forecast_type'] == "Direct" && User::isManager($reportee->id)) {
             // this is the manager committing their own data, the $reports_to should be them
             // and not their actual manager
             $reports_to = $reportee->id;
         } else {
             if ($data['forecast_type'] == "Rollup" && $reports_to == $reportee->id) {
                 // if type is rollup and reports_to is equal to the $reportee->id (aka no top level manager),
                 // we don't want to update their draft record so just ignore this,
                 return false;
             }
         }
     }
     if (isset($data['draft']) && $data['draft'] == '1' && $GLOBALS['current_user']->id == $reportee->id) {
         // this data is for the current user, but is not a commit so we need to update their own draft record
         $reports_to = $reportee->id;
     }
     $this->retrieve_by_string_fields(array('user_id' => $reportee->id, 'assigned_user_id' => $reports_to, 'timeperiod_id' => $data['timeperiod_id'], 'draft' => 1, 'deleted' => 0));
     $copyMap = array('currency_id', 'base_rate', 'timeperiod_id', 'opp_count', 'pipeline_opp_count', 'pipeline_amount', 'closed_amount');
     if ($data["forecast_type"] == "Direct") {
         $copyMap[] = "likely_case";
         $copyMap[] = "best_case";
         $copyMap[] = "worst_case";
     } else {
         if ($data["forecast_type"] == "Rollup") {
             $copyMap[] = array("likely_case" => "likely_adjusted");
             $copyMap[] = array("best_case" => "best_adjusted");
             $copyMap[] = array("worst_case" => "worst_adjusted");
         }
     }
     if (empty($this->id) || $this->manager_saved == false) {
         if ($data["forecast_type"] == "Rollup") {
             $copyMap[] = array('likely_case_adjusted' => 'likely_adjusted');
             $copyMap[] = array('best_case_adjusted' => 'best_adjusted');
             $copyMap[] = array('worst_case_adjusted' => 'worst_adjusted');
         } elseif ($data["forecast_type"] == "Direct") {
             $copyMap[] = array('likely_case_adjusted' => 'likely_case');
             $copyMap[] = array('best_case_adjusted' => 'best_case');
             $copyMap[] = array('worst_case_adjusted' => 'worst_case');
         }
     }
     if (empty($this->id)) {
         if (!isset($data['quota']) || empty($data['quota'])) {
             // we need to get a fresh bean to store the quota if one exists
             $quotaSeed = BeanFactory::getBean('Quotas');
             // check if we need to get the roll up amount
             $getRollupQuota = User::isManager($reportee->id) && isset($data['forecast_type']) && $data['forecast_type'] == 'Rollup';
             $quota = $quotaSeed->getRollupQuota($data['timeperiod_id'], $reportee->id, $getRollupQuota);
             $data['quota'] = $quota['amount'];
         }
         $copyMap[] = "quota";
     }
     $this->copyValues($copyMap, $data);
     // set the team to the default ones from the passed in user
     $this->team_set_id = $reportee->team_set_id;
     $this->team_id = $reportee->team_id;
     $this->name = $reportee->full_name;
     $this->user_id = $reportee->id;
     $this->assigned_user_id = $reports_to;
     $this->draft = 1;
     $this->save();
     // roll up the draft value for best/likely/worst case values to the committed record if one exists
     $this->rollupDraftToCommittedWorksheet($this);
     return true;
 }
 /**
  * Utility Method to create the filter for the filer API to use
  *
  * @param ServiceBase $api                  Service Api Class
  * @param mixed $user_id                    Passed in User ID, if false, it will use the current use from $api->user
  * @param mixed $timeperiod_id              TimePeriod Id, if false, the current time period will be found an used
  * @return array                            The Filer array to be passed back into the filerList Api
  * @throws SugarApiExceptionNotAuthorized
  * @throws SugarApiExceptionInvalidParameter
  */
 protected function createFilter(ServiceBase $api, $user_id, $timeperiod_id)
 {
     // we need to check if the $api->user is a manager
     // if they are not a manager, throw back a 403 (Not Authorized) error
     if (!User::isManager($api->user->id)) {
         throw new SugarApiExceptionNotAuthorized();
     }
     $filter = array();
     // default draft to be 1
     $draft = 1;
     // if we did not find a user in the filters array, set it to the current user's id
     if ($user_id == false) {
         // use the current user, since on one was passed in
         $user_id = $api->user->id;
     } else {
         // make sure that the passed in user is a valid user
         /* @var $user User */
         // we use retrieveBean so it will return NULL and not an empty bean if the $args['user_id'] is invalid
         $user = BeanFactory::retrieveBean('Users', $user_id);
         if (is_null($user)) {
             throw new SugarApiExceptionInvalidParameter('Provided User is not valid');
         }
         // we found a user, so check to make sure that if it's not the current user, they only see committed data
         $draft = $user_id == $api->user->id ? 1 : 0;
     }
     // todo-sfa: Make sure that the passed in user can be viewed by the $api->user, need to check reportee tree
     // set the assigned_user_id
     array_push($filter, array('assigned_user_id' => $user_id));
     // set the draft flag depending on the assigned_user_id that is set from above
     array_push($filter, array('draft' => $draft));
     // if we didn't find a time period, set the time period to be the current time period
     if (!is_guid($timeperiod_id) && is_numeric($timeperiod_id) && $timeperiod_id != 0) {
         // we have a timestamp, find timeperiod it belongs in
         $timeperiod_id = TimePeriod::getIdFromTimestamp($timeperiod_id);
     }
     if (!is_guid($timeperiod_id)) {
         $timeperiod_id = TimePeriod::getCurrentId();
     }
     // fix up the timeperiod filter
     /* @var $tp TimePeriod */
     // we use retrieveBean so it will return NULL and not an empty bean if the $args['timeperiod_id'] is invalid
     $tp = BeanFactory::retrieveBean('TimePeriods', $timeperiod_id);
     if (is_null($tp)) {
         throw new SugarApiExceptionInvalidParameter('Provided TimePeriod is not valid');
     }
     array_push($filter, array('timeperiod_id' => $tp->id));
     return $filter;
 }
 /**
  * Utility Method to create the filter for the filer API to use
  *
  * @param ServiceBase $api                  Service Api Class
  * @param mixed $user_id                    Passed in User ID, if false, it will use the current use from $api->user
  * @param mixed $timeperiod_id              TimePeriod Id, if false, the current time period will be found an used
  * @param string $parent_type               Type of worksheet to return, defaults to 'opportunities', but can be 'products'
  * @return array                            The Filer array to be passed back into the filerList Api
  * @throws SugarApiExceptionNotAuthorized
  * @throws SugarApiExceptionInvalidParameter
  */
 protected function createFilter(ServiceBase $api, $user_id, $timeperiod_id, $parent_type = 'Opportunities')
 {
     $filter = array();
     // default draft to be 1
     $draft = 1;
     // if we did not find a user in the filters array, set it to the current user's id
     if ($user_id == false) {
         // use the current user, since on one was passed in
         $user_id = $api->user->id;
     } else {
         // make sure that the passed in user is a valid user
         /* @var $user User */
         // we use retrieveBean so it will return NULL and not an empty bean if the $args['user_id'] is invalid
         $user = BeanFactory::retrieveBean('Users', $user_id);
         if (is_null($user)) {
             throw new SugarApiExceptionInvalidParameter('Provided User is not valid');
         }
         // we found a user, so check to make sure that if it's not the current user, they only see committed data
         $draft = $user_id == $api->user->id ? 1 : 0;
     }
     // so we have a valid user, and it's not the $api->user, we need to check if the $api->user is a manager
     // if they are not a manager, throw back a 403 (Not Authorized) error
     if ($draft == 0 && !User::isManager($api->user->id)) {
         throw new SugarApiExceptionNotAuthorized();
     }
     // todo-sfa: Make sure that the passed in user can be viewed by the $api->user, need to check reportee tree
     // set the assigned_user_id
     array_push($filter, array('assigned_user_id' => $user_id));
     // set the draft flag depending on the assigned_user_id that is set from above
     array_push($filter, array('draft' => $draft));
     // if we didn't find a time period, set the time period to be the current time period
     if (!is_guid($timeperiod_id) && is_numeric($timeperiod_id) && $timeperiod_id != 0) {
         // we have a timestamp, find timeperiod it belongs in
         $timeperiod_id = TimePeriod::getIdFromTimestamp($timeperiod_id);
     }
     if (!is_guid($timeperiod_id)) {
         $timeperiod_id = TimePeriod::getCurrentId();
     }
     // fix up the timeperiod filter
     /* @var $tp TimePeriod */
     // we use retrieveBean so it will return NULL and not an empty bean if the $args['timeperiod_id'] is invalid
     $tp = BeanFactory::retrieveBean('TimePeriods', $timeperiod_id);
     if (is_null($tp)) {
         throw new SugarApiExceptionInvalidParameter('Provided TimePeriod is not valid');
     }
     array_push($filter, array('$and' => array(array('date_closed_timestamp' => array('$gte' => $tp->start_date_timestamp)), array('date_closed_timestamp' => array('$lte' => $tp->end_date_timestamp)))));
     if (empty($parent_type)) {
         // get the forecast_by setting
         /* @var $admin Administration */
         $admin = BeanFactory::getBean('Administration');
         $settings = $admin->getConfigForModule('Forecasts', $api->platform);
         $parent_type = $settings['forecast_by'];
     }
     // we only want to view parent_types of 'Opportunities' here
     array_push($filter, array('parent_type' => $parent_type));
     return $filter;
 }