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;
 }
 function display()
 {
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     if ($this->fromModuleBuilder) {
         return;
         //no support for MB
     }
     global $current_user;
     global $mod_strings;
     $smarty = new Sugar_Smarty();
     $smarty->assign('title', $mod_strings['LBL_DEVELOPER_TOOLS']);
     $smarty->assign('question', $mod_strings['LBL_REMOVE_LAYOUT']);
     $smarty->assign('mod_strings', $mod_strings);
     $module_name = $_REQUEST['view_module'];
     $smarty->assign('view_module', $module_name);
     $groupLayout = $_REQUEST['grpLayout'];
     $smarty->assign('groupLayout', $groupLayout);
     require_once 'modules/SecurityGroups/SecurityGroup.php';
     $groupFocus = new SecurityGroup();
     $groupFocus->retrieve($groupLayout);
     $groupName = $groupFocus->name;
     // set up language files
     //$smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
     //$smarty->assign('from_mb',$this->fromModuleBuilder);
     $mb = new ModuleBuilder();
     if (!isset($_REQUEST['view_package'])) {
         $_REQUEST['view_package'] = 'studio';
     }
     $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
     $package = $mb->packages[$_REQUEST['view_package']];
     $package->loadModuleTitles();
     $ajax = new AjaxCompose();
     $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
     $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate('LBL_LAYOUTS', 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=addlayout&layouts=1&view_module=' . $module_name . '")');
     $ajax->addCrumb(translate($groupName), '');
     $ajax->addCrumb($mod_strings['LBL_REMOVE_LAYOUT'], '');
     //$ajax->addSection ( 'center', $moduleName . ' ' . translate('LBL_ADD_LAYOUT'),
     $ajax->addSection('center', $mod_strings['LBL_ADD_LAYOUT'], $smarty->fetch('modules/ModuleBuilder/tpls/removegrouplayoutprompt.tpl'));
     echo $ajax->getJavascript();
 }
 private function getAssignableUsers()
 {
     if ($this->distributionMethod == 'singleUser') {
         return array();
     }
     $distributionOptions = $this->getDistributionOptions();
     if (empty($distributionOptions)) {
         return array();
     }
     switch ($distributionOptions[0]) {
         case 'security_group':
             if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
                 require_once 'modules/SecurityGroups/SecurityGroup.php';
                 $security_group = new SecurityGroup();
                 $security_group->retrieve($distributionOptions[1]);
                 $group_users = $security_group->get_linked_beans('users', 'User');
                 $users = array();
                 $r_users = array();
                 if ($distributionOptions[2] != '') {
                     $r_users = $this->getRoleUsers($distributionOptions[2]);
                 }
                 foreach ($group_users as $group_user) {
                     if ($distributionOptions[2] != '' && !isset($r_users[$group_user->id])) {
                         continue;
                     }
                     $users[$group_user->id] = $group_user->name;
                 }
                 break;
             }
             //No Security Group module found - fall through.
         //No Security Group module found - fall through.
         case 'role':
             $users = $this->getRoleUsers($distributionOptions[2]);
             break;
         case 'all':
         default:
             $users = get_user_array(false);
             break;
     }
     return $users;
 }
 function display($preview = false)
 {
     $packageName = isset($_REQUEST['view_package']) ? $_REQUEST['view_package'] : '';
     require_once 'modules/ModuleBuilder/parsers/ParserFactory.php';
     $parser = ParserFactory::getParser($this->editLayout, $this->editModule, $packageName);
     $smarty = parent::constructSmarty($parser);
     $smarty->assign('action', 'searchViewSave');
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('helpName', 'searchViewEditor');
     $smarty->assign('helpDefault', 'modify');
     /* BEGIN - SECURITY GROUPS */
     $groupLayout = "";
     if (!empty($_REQUEST['grpLayout'])) {
         $groupLayout = $_REQUEST['grpLayout'];
     }
     global $groupName;
     $groupName = "Default";
     if (!isset($groupLayout) || empty($groupLayout)) {
         $groupLayout = "";
     } else {
         //Get group name for display
         require_once 'modules/SecurityGroups/SecurityGroup.php';
         $groupFocus = new SecurityGroup();
         $groupFocus->retrieve($groupLayout);
         $groupName = $groupFocus->name;
     }
     $smarty->assign('grpLayout', $groupLayout);
     /* END - SECURITY GROUPS */
     if ($preview) {
         echo $smarty->fetch("modules/ModuleBuilder/tpls/Preview/listView.tpl");
     } else {
         $ajax = $this->constructAjax();
         $ajax->addSection('center', translate($this->title), $smarty->fetch("modules/ModuleBuilder/tpls/listView.tpl"));
         echo $ajax->getJavascript();
     }
 }
 function getGroupLayouts()
 {
     $views = $this->getViews();
     //$defaultLayout [] = array ( 'name' => translate('LBL_DEFAULT') , 'type' => 'Folder' , 'children' => $layouts , 'action' => 'module=ModuleBuilder&action=wizard&layouts=1&view_module=' . $this->module ) ;
     //$layout_nodes[] = array ( 'name' => translate($groupFocus->name) , 'type' => 'Folder' , 'children' => $group_layouts , 'action' => 'module=ModuleBuilder&action=wizard&layouts=1&view_module=' . $this->module . "&grpLayout=".$groupFocus->id ) ;
     //translate('LBL_LAYOUTS') => array ( 'children' => 'getLayouts' , 'action' => "module=ModuleBuilder&action=wizard&view=layouts&view_module={$this->module}" , 'imageTitle' => 'Layouts' , 'help' => 'layoutsBtn' ) ,
     $defaultLayout[] = array('name' => translate('LBL_DEFAULT'), 'type' => 'Folder', 'children' => $this->getLayouts(), 'action' => "module=ModuleBuilder&action=wizard&view=layouts&view_module={$this->module}", 'imageTitle' => 'Layouts', 'help' => 'layoutsBtn');
     $layout_nodes = array();
     $layout_nodes = $defaultLayout;
     //get security group nodes...in metadata directory in a folder named with the guid of the security group
     $custDirectory = "custom/modules/" . $this->module . "/metadata/";
     if (is_dir($custDirectory)) {
         require_once 'modules/SecurityGroups/SecurityGroup.php';
         $groupFocus = new SecurityGroup();
         $d = dir($custDirectory);
         while ($f = $d->read()) {
             if ($f == "." || $f == "..") {
                 continue;
             }
             if (is_dir("{$custDirectory}/{$f}")) {
                 //see if $f is a guid for a security group
                 $groupFocus = new SecurityGroup();
                 $groupFocus->retrieve($f);
                 if (!empty($groupFocus->id) && isset($groupFocus->id)) {
                     //found existing group layout...create node
                     $GLOBALS['log']->debug("Found Security Group Layout for: " . $groupFocus->name);
                     $group_layouts = array();
                     //remove group layout option
                     $group_layouts[] = array('name' => translate('LBL_REMOVE_LAYOUT'), 'action' => "module=ModuleBuilder&action=removeGroupLayoutPrompt&view_module={$this->module}" . "&grpLayout=" . $groupFocus->id);
                     foreach ($views as $def) {
                         $group_layouts[$def['name']] = array('name' => $def['name'], 'action' => "module=ModuleBuilder&action=editLayout&view={$def['type']}&view_module={$this->module}&grpLayout=" . $groupFocus->id, 'imageTitle' => $def['image'], 'help' => "viewBtn{$def['type']}", 'size' => '48');
                     }
                     if ($this->isValidDashletModule($this->module)) {
                         $dashlets = array();
                         $dashlets[] = array('name' => translate('LBL_DASHLETLISTVIEW'), 'type' => 'dashlet', 'action' => 'module=ModuleBuilder&action=editLayout&view=dashlet&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                         $dashlets[] = array('name' => translate('LBL_DASHLETSEARCHVIEW'), 'type' => 'dashletsearch', 'action' => 'module=ModuleBuilder&action=editLayout&view=dashletsearch&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                         $group_layouts[translate('LBL_DASHLET')] = array('name' => translate('LBL_DASHLET'), 'type' => 'Folder', 'children' => $dashlets, 'imageTitle' => 'Dashlet', 'action' => 'module=ModuleBuilder&action=wizard&view=dashlet&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                     }
                     //For popup tree node
                     $popups = array();
                     $popups[] = array('name' => translate('LBL_POPUPLISTVIEW'), 'type' => 'popuplistview', 'action' => 'module=ModuleBuilder&action=editLayout&view=popuplist&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                     $popups[] = array('name' => translate('LBL_POPUPSEARCH'), 'type' => 'popupsearch', 'action' => 'module=ModuleBuilder&action=editLayout&view=popupsearch&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                     $group_layouts[translate('LBL_POPUP')] = array('name' => translate('LBL_POPUP'), 'type' => 'Folder', 'children' => $popups, 'imageTitle' => 'Popup', 'imageName' => 'icon_Popup.gif', 'action' => 'module=ModuleBuilder&action=wizard&view=popup&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                     $nodes = $this->getSearch($groupFocus->id);
                     if (!empty($nodes)) {
                         $group_layouts[translate('LBL_SEARCH')] = array('name' => translate('LBL_SEARCH'), 'type' => 'Folder', 'children' => $nodes, 'action' => "module=ModuleBuilder&action=wizard&view=search&view_module={$this->module}&grpLayout=" . $groupFocus->id, 'imageTitle' => 'SearchForm', 'help' => 'searchBtn', 'size' => '48');
                     }
                     $layout_nodes[] = array('name' => translate($groupFocus->name), 'type' => 'Folder', 'children' => $group_layouts, 'action' => 'module=ModuleBuilder&action=wizard&&view=layouts&view_module=' . $this->module . "&grpLayout=" . $groupFocus->id);
                 }
             }
         }
         //end while files/dirs
     }
     //end if directory exists
     //$layouts [ translate('LBL_LAYOUTS') ] = array ( 'name' => translate('LBL_LAYOUTS') , 'type' => 'Folder' , 'children' => $layout_nodes , 'action' => "module=ModuleBuilder&action=addlayout&layouts=1&view_module={$this->module}") ;
     //$nodes [ 'children' ] [] = array ( 'name' => translate('LBL_LAYOUTS') , 'type' => 'Folder' , 'children' => $layout_nodes , 'action' => 'module=ModuleBuilder&action=addlayout&layouts=1&view_module=' . $this->module ) ;
     return $layout_nodes;
 }
 function display($preview = false)
 {
     global $mod_strings;
     $parser = ParserFactory::getParser($this->editLayout, $this->editModule, $this->package);
     $history = $parser->getHistory();
     $smarty = new Sugar_Smarty();
     //Add in the module we are viewing to our current mod strings
     if (!$this->fromModuleBuilder) {
         global $current_language;
         $editModStrings = return_module_language($current_language, $this->editModule);
         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
     }
     $smarty->assign('mod', $mod_strings);
     $smarty->assign('MOD', $mod_strings);
     // assign buttons
     $images = array('icon_save' => 'studio_save', 'icon_publish' => 'studio_publish', 'icon_address' => 'icon_Address', 'icon_emailaddress' => 'icon_EmailAddress', 'icon_phone' => 'icon_Phone');
     foreach ($images as $image => $file) {
         $smarty->assign($image, SugarThemeRegistry::current()->getImage($file));
     }
     /* BEGIN - SECURITY GROUPS */
     $groupLayout = "";
     if (!empty($_REQUEST['grpLayout'])) {
         $groupLayout = $_REQUEST['grpLayout'];
     }
     $groupName = "Default";
     if (!isset($groupLayout) || empty($groupLayout)) {
         $groupLayout = "";
     } else {
         //Get group name for display
         require_once 'modules/SecurityGroups/SecurityGroup.php';
         $groupFocus = new SecurityGroup();
         $groupFocus->retrieve($groupLayout);
         $groupName = $groupFocus->name;
     }
     $smarty->assign('grpLayout', $groupLayout);
     /* END - SECURITY GROUPS */
     $requiredFields = implode($parser->getRequiredFields(), ',');
     $slashedRequiredFields = addslashes($requiredFields);
     $buttons = array();
     $disableLayout = false;
     if ($preview) {
         $smarty->assign('layouttitle', translate('LBL_LAYOUT_PREVIEW', 'ModuleBuilder'));
     } else {
         $smarty->assign('layouttitle', translate('LBL_CURRENT_LAYOUT', 'ModuleBuilder'));
         if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) {
             $parser2 = ParserFactory::getParser(MB_EDITVIEW, $this->editModule, $this->package);
             if ($this->editLayout == MB_DETAILVIEW) {
                 $disableLayout = $parser2->getSyncDetailEditViews();
             }
             if (!empty($_REQUEST['copyFromEditView'])) {
                 $editViewPanels = $parser2->convertFromCanonicalForm($parser2->_viewdefs['panels'], $parser2->_fielddefs);
                 $parser->_viewdefs['panels'] = $editViewPanels;
                 $parser->_fielddefs = $parser2->_fielddefs;
                 $parser->setUseTabs($parser2->getUseTabs());
             }
         }
         if (!$this->fromModuleBuilder) {
             $buttons[] = array('id' => 'saveBtn', 'text' => translate('LBL_BTN_SAVE'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'publishBtn', 'text' => translate('LBL_BTN_SAVEPUBLISH'), 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'spacer', 'width' => '33px');
             $buttons[] = array('id' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'", 'disabled' => $disableLayout);
         } else {
             $buttons[] = array('id' => 'saveBtn', 'text' => $GLOBALS['mod_strings']['LBL_BTN_SAVE'], 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'spacer', 'width' => '33px');
             $buttons[] = array('id' => 'historyBtn', 'text' => translate('LBL_HISTORY'), 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
             $buttons[] = array('id' => 'historyDefault', 'text' => translate('LBL_RESTORE_DEFAULT'), 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'", 'disabled' => $disableLayout);
         }
         if ($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE) {
             $buttons[] = array('id' => 'copyFromEditView', 'text' => translate('LBL_COPY_FROM_EDITVIEW'), 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'", 'disabled' => $disableLayout);
         }
     }
     $html = "";
     foreach ($buttons as $button) {
         if ($button['id'] == "spacer") {
             $html .= "<td style='width:{$button['width']}'> </td>";
         } else {
             $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' " . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' " . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'";
             if (!empty($button['disabled'])) {
                 $html .= " disabled";
             }
             $html .= "></td>";
         }
     }
     $smarty->assign('buttons', $html);
     // assign fields and layout
     $smarty->assign('available_fields', $parser->getAvailableFields());
     $smarty->assign('disable_layout', $disableLayout);
     $smarty->assign('required_fields', $requiredFields);
     $smarty->assign('layout', $parser->getLayout());
     $smarty->assign('field_defs', $parser->getFieldDefs());
     $smarty->assign('view_module', $this->editModule);
     $smarty->assign('view', $this->editLayout);
     $smarty->assign('maxColumns', $parser->getMaxColumns());
     $smarty->assign('nextPanelId', $parser->getFirstNewPanelId());
     $smarty->assign('displayAsTabs', $parser->getUseTabs());
     $smarty->assign('syncDetailEditViews', $parser->getSyncDetailEditViews());
     $smarty->assign('fieldwidth', 150);
     $smarty->assign('translate', $this->fromModuleBuilder ? false : true);
     if ($this->fromModuleBuilder) {
         $smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
         $smarty->assign('view_package', $this->package);
     }
     $labels = array(MB_EDITVIEW => 'LBL_EDITVIEW', MB_DETAILVIEW => 'LBL_DETAILVIEW', MB_QUICKCREATE => 'LBL_QUICKCREATE');
     $layoutLabel = 'LBL_LAYOUTS';
     $layoutView = 'layouts';
     $ajax = new AjaxCompose();
     $viewType;
     $translatedViewType = '';
     if (isset($labels[strtolower($this->editLayout)])) {
         $translatedViewType = translate($labels[strtolower($this->editLayout)], 'ModuleBuilder');
     }
     if ($this->fromModuleBuilder) {
         $ajax->addCrumb(translate('LBL_MODULEBUILDER', 'ModuleBuilder'), 'ModuleBuilder.main("mb")');
         $ajax->addCrumb($this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")');
         $ajax->addCrumb($this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '&view_package=' . $this->package . '")');
         $ajax->addCrumb($translatedViewType, '');
     } else {
         $ajax->addCrumb(translate('LBL_STUDIO', 'ModuleBuilder'), 'ModuleBuilder.main("studio")');
         $ajax->addCrumb($this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")');
         $ajax->addCrumb(translate($layoutLabel, 'ModuleBuilder'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=' . $layoutView . '&view_module=' . $this->editModule . '")');
         /* BEGIN - SECURITY GROUPS */
         $ajax->addCrumb(translate($groupName), '');
         /* END - SECURITY GROUPS */
         $ajax->addCrumb($translatedViewType, '');
     }
     // set up language files
     $smarty->assign('language', $parser->getLanguage());
     // for sugar_translate in the smarty template
     $smarty->assign('from_mb', $this->fromModuleBuilder);
     $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
     if ($this->fromModuleBuilder) {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($this->package, $this->editModule);
         $smarty->assign('current_mod_strings', $module->getModStrings());
     }
     $ajax->addSection('center', $translatedViewType, $smarty->fetch('modules/ModuleBuilder/tpls/layoutView.tpl'));
     if ($preview) {
         echo $smarty->fetch('modules/ModuleBuilder/tpls/Preview/layoutView.tpl');
     } else {
         echo $ajax->getJavascript();
     }
 }
 function get_email_recipients()
 {
     $params = unserialize(base64_decode($this->email_recipients));
     $emails = array();
     if (isset($params['email_target_type'])) {
         foreach ($params['email_target_type'] as $key => $field) {
             switch ($field) {
                 case 'Email Address':
                     $emails[] = $params['email'][$key];
                     break;
                 case 'Specify User':
                     $user = new User();
                     $user->retrieve($params['email'][$key]);
                     $emails[] = $user->emailAddress->getPrimaryAddress($user);
                     break;
                 case 'Users':
                     $users = array();
                     switch ($params['email'][$key][0]) {
                         case 'security_group':
                             if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
                                 require_once 'modules/SecurityGroups/SecurityGroup.php';
                                 $security_group = new SecurityGroup();
                                 $security_group->retrieve($params['email'][$key][1]);
                                 $users = $security_group->get_linked_beans('users', 'User');
                                 $r_users = array();
                                 if ($params['email'][$key][2] != '') {
                                     require_once 'modules/ACLRoles/ACLRole.php';
                                     $role = new ACLRole();
                                     $role->retrieve($params['email'][$key][2]);
                                     $role_users = $role->get_linked_beans('users', 'User');
                                     foreach ($role_users as $role_user) {
                                         $r_users[$role_user->id] = $role_user->name;
                                     }
                                 }
                                 foreach ($users as $user_id => $user) {
                                     if ($params['email'][$key][2] != '' && !isset($r_users[$user->id])) {
                                         unset($users[$user_id]);
                                     }
                                 }
                                 break;
                             }
                             //No Security Group module found - fall through.
                         //No Security Group module found - fall through.
                         case 'role':
                             require_once 'modules/ACLRoles/ACLRole.php';
                             $role = new ACLRole();
                             $role->retrieve($params['email'][$key][2]);
                             $users = $role->get_linked_beans('users', 'User');
                             break;
                         case 'all':
                         default:
                             global $db;
                             $sql = "SELECT id from users WHERE status='Active' AND portal_only=0 ";
                             $result = $db->query($sql);
                             while ($row = $db->fetchByAssoc($result)) {
                                 $user = new User();
                                 $user->retrieve($row['id']);
                                 $users[$user->id] = $user;
                             }
                             break;
                     }
                     foreach ($users as $user) {
                         $emails[] = $user->emailAddress->getPrimaryAddress($user);
                     }
                     break;
             }
         }
     }
     return $emails;
 }
function template_calendar($args)
{
    global $timedate;
    if (isset($args['size']) && $args['size'] == 'small') {
        $args['calendar']->show_activities = false;
        $args['calendar']->show_week_on_month_view = false;
    }
    $newargs = array();
    $newargs['view'] = $args['view'];
    $newargs['calendar'] = $args['calendar'];
    if (!isset($args['size']) || $args['size'] != 'small') {
        template_cal_tabs($newargs);
    }
    if (isset($_REQUEST['view']) && $_REQUEST['view'] == 'shared') {
        global $ids;
        global $current_user;
        global $mod_strings;
        global $app_list_strings, $current_language, $currentModule, $action, $app_strings;
        $current_module_strings = return_module_language($current_language, 'Calendar');
        $ids = array();
        $user_ids = $current_user->getPreference('shared_ids');
        //get list of user ids for which to display data
        if (!empty($user_ids) && count($user_ids) != 0 && !isset($_REQUEST['shared_ids'])) {
            $ids = $user_ids;
        } elseif (isset($_REQUEST['shared_ids']) && count($_REQUEST['shared_ids']) > 0) {
            $ids = $_REQUEST['shared_ids'];
            $current_user->setPreference('shared_ids', $_REQUEST['shared_ids']);
        } else {
            //$ids = get_user_array(false);
            //$ids = array_keys($ids);
            $ids = array($current_user->id);
        }
        //get team id for which to display user list
        $tools = '<div align="right"><a href="index.php?module=' . $currentModule . '&action=' . $action . '&view=shared" class="tabFormAdvLink">&nbsp;<a href="javascript: toggleDisplay(\'shared_cal_edit\');" class="tabFormAdvLink">' . SugarThemeRegistry::current()->getImage('edit', 'alt="' . $current_module_strings['LBL_EDIT'] . '"  border="0"  align="absmiddle"') . '&nbsp;' . $current_module_strings['LBL_EDIT'] . '</a></div>';
        echo get_form_header($mod_strings['LBL_SHARED_CAL_TITLE'], $tools, false);
        if (empty($_SESSION['shared_ids'])) {
            $_SESSION['shared_ids'] = "";
        }
        echo "\n\t\t\t<script language=\"javascript\">\n\t\t\tfunction up(name) {\n\t\t\t\tvar td = document.getElementById(name+'_td');\n\t\t\t\tvar obj = td.getElementsByTagName('select')[0];\n\t\t\t\tobj =(typeof obj == \"string\") ? document.getElementById(obj) : obj;\n\t\t\t\tif(obj.tagName.toLowerCase() != \"select\" && obj.length < 2)\n\t\t\t\t\treturn false;\n\t\t\t\tvar sel = new Array();\n\n\t\t\t\tfor(i=0; i<obj.length; i++) {\n\t\t\t\t\tif(obj[i].selected == true) {\n\t\t\t\t\t\tsel[sel.length] = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(i in sel) {\n\t\t\t\t\tif(sel[i] != 0 && !obj[sel[i]-1].selected) {\n\t\t\t\t\t\tvar tmp = new Array(obj[sel[i]-1].text, obj[sel[i]-1].value);\n\t\t\t\t\t\tobj[sel[i]-1].text = obj[sel[i]].text;\n\t\t\t\t\t\tobj[sel[i]-1].value = obj[sel[i]].value;\n\t\t\t\t\t\tobj[sel[i]].text = tmp[0];\n\t\t\t\t\t\tobj[sel[i]].value = tmp[1];\n\t\t\t\t\t\tobj[sel[i]-1].selected = true;\n\t\t\t\t\t\tobj[sel[i]].selected = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction down(name) {\n\t\t\t\tvar td = document.getElementById(name+'_td');\n\t\t\t\tvar obj = td.getElementsByTagName('select')[0];\n\t\t\t\tif(obj.tagName.toLowerCase() != \"select\" && obj.length < 2)\n\t\t\t\t\treturn false;\n\t\t\t\tvar sel = new Array();\n\t\t\t\tfor(i=obj.length-1; i>-1; i--) {\n\t\t\t\t\tif(obj[i].selected == true) {\n\t\t\t\t\t\tsel[sel.length] = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(i in sel) {\n\t\t\t\t\tif(sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {\n\t\t\t\t\t\tvar tmp = new Array(obj[sel[i]+1].text, obj[sel[i]+1].value);\n\t\t\t\t\t\tobj[sel[i]+1].text = obj[sel[i]].text;\n\t\t\t\t\t\tobj[sel[i]+1].value = obj[sel[i]].value;\n\t\t\t\t\t\tobj[sel[i]].text = tmp[0];\n\t\t\t\t\t\tobj[sel[i]].value = tmp[1];\n\t\t\t\t\t\tobj[sel[i]+1].selected = true;\n\t\t\t\t\t\tobj[sel[i]].selected = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t</script>\n\n\t\t\t<div id='shared_cal_edit' style='display: none;'>\n\t\t\t<form name='shared_cal' action=\"index.php\" method=\"post\" >\n\t\t\t<input type=\"hidden\" name=\"module\" value=\"" . $currentModule . "\">\n\t\t\t<input type=\"hidden\" name=\"action\" value=\"" . $action . "\">\n\t\t\t<input type=\"hidden\" name=\"view\" value=\"shared\">\n\t\t\t<input type=\"hidden\" name=\"edit\" value=\"0\">\n\t\t\t<table cellpadding=\"0\" cellspacing=\"3\" border=\"0\" align=\"center\">\n\t\t\t<tr><th valign=\"top\"  align=\"center\" colspan=\"2\">\n\t\t\t";
        echo $current_module_strings['LBL_SELECT_USERS'];
        echo "\n\t\t\t</th>\n\t\t\t</tr>\n\t\t\t<tr><td valign=\"top\">";
        /** BEGIN - SECURITY GROUPS */
        $securitygroup = $current_user->getPreference('securitygroup_id');
        if (!empty($securitygroup) && !isset($_REQUEST['securitygroup_id'])) {
            $securitygroup_id = $securitygroup;
        } elseif (isset($_REQUEST['securitygroup_id'])) {
            $securitygroup_id = $_REQUEST['securitygroup_id'];
            $current_user->setPreference('securitygroup_id', $_REQUEST['securitygroup_id']);
        } else {
            $securitygroup_id = '';
        }
        if (empty($_SESSION['securitygroup_id'])) {
            $_SESSION['securitygroup_id'] = "";
        }
        echo "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" class=\"chartForm\" align=\"center\">\n\t\t\t<tr>\n\t\t\t\t<td valign='top' nowrap><b>" . $current_module_strings['LBL_SECURITYGROUPS'] . "></b></td>\n\t\t\t\t<td valign='top' id=\"teams\"><select id=\"securitygroup_id\" onchange='this.form.edit.value=1; this.form.submit();' name=\"securitygroup_id\">";
        global $current_user;
        require_once "modules/SecurityGroups/SecurityGroup.php";
        $group_array[""] = "";
        //for --None-- option
        if (is_admin($current_user)) {
            $securitygroups = SecurityGroup::getAllSecurityGroups();
            foreach ($securitygroups as $group) {
                $group_array[$group['id']] = $group['name'];
            }
        } else {
            $securitygroups = SecurityGroup::getUserSecurityGroups($current_user->id);
            foreach ($securitygroups as $group) {
                $group_array[$group['id']] = $group['name'];
            }
        }
        echo get_select_options_with_id($group_array, $securitygroup_id);
        echo "</select></td>\n\t\t\t</tr>\n\t\t\t</table>";
        /** END - SECURITY GROUPS */
        echo "\n            </td><td valign=\"top\">\n\n\t\t\t<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\" class=\"edit view\" align=\"center\">\n\t\t\t<tr>\n\t\t\t\t<td valign='top' nowrap><b>" . $current_module_strings['LBL_USERS'] . "</b></td>\n\t\t\t\t<td valign='top' id=\"shared_ids_td\"><select id=\"shared_ids\" name=\"shared_ids[]\" multiple size='3'>";
        /** BEGIN - SECURITY GROUPS */
        if (!empty($securitygroup_id)) {
            require_once 'modules/SecurityGroups/SecurityGroup.php';
            $securitygroup = new SecurityGroup();
            $securitygroup->retrieve($securitygroup_id);
            $users_array = $securitygroup->getMembers();
            $user_ids = array();
            foreach ($users_array as $user) {
                $user_ids[$user['id']] = $user['user_name'];
            }
            echo get_select_options_with_id($user_ids, $ids);
        } else {
            echo get_select_options_with_id(get_user_array(false), $ids);
        }
        /** END - SECURITY GROUPS */
        echo "\t</select></td>\n\t\t\t\t<td><a onclick=\"up('shared_ids');\">" . SugarThemeRegistry::current()->getImage('uparrow_big', 'border="0" style="margin-bottom: 1px;" alt="' . $app_strings['LBL_SORT'] . '"') . "</a><br>\n\t\t\t\t<a onclick=\"down('shared_ids');\">" . SugarThemeRegistry::current()->getImage('downarrow_big', 'border="0" style="margin-top: 1px;"  alt="' . $app_strings['LBL_SORT'] . '"') . "</a></td>\n\t\t\t</tr>\n\t\t\t<tr>";
        echo "<td align=\"right\" colspan=\"2\"><input class=\"button\" type=\"submit\" title=\"" . $app_strings['LBL_SELECT_BUTTON_TITLE'] . "\" accessKey=\"" . $app_strings['LBL_SELECT_BUTTON_KEY'] . "\" value=\"" . $app_strings['LBL_SELECT_BUTTON_LABEL'] . "\" /><input class=\"button\" onClick=\"javascript: toggleDisplay('shared_cal_edit');\" type=\"button\" title=\"" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "\" accessKey=\"" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "\" value=\"" . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . "\"/></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td></tr>\n\t\t\t</table>\n\t\t\t</form>";
    }
    // end "shared" view
    echo "</div></p>";
    if (isset($_REQUEST['edit']) && $_REQUEST['edit']) {
        echo " <script language=\"javascript\"> toggleDisplay('shared_cal_edit'); </script>";
    }
    echo "\n\t\t<table id=\"daily_cal_table_outside\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"monthBox\">\n\t\t<tr>\n\t\t<td>\n\t\t  <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"monthHeader\">\n\t\t  <tr>\n\t\t  <td width=\"1%\" nowrap>";
    if (!isset($args['size']) || $args['size'] != 'small') {
        template_get_previous_calendar($args);
    }
    echo "\n\t\t  </td>\n\t\t  <td width=\" 98 % \" align=center scope='row'>";
    if (isset($args['size']) && ($args['size'] = 'small')) {
        ?>
		<a style="text-decoration: none;"
			href="index.php?module=Calendar&action=index&view=month<?php 
        echo $args['calendar']->date_time->get_date_str();
        ?>
">
<?php 
    }
    ?>
<h3>
<?php 
    template_echo_date_info($args['view'], $args['calendar']->date_time);
    ?>
</h3>
<?php 
    if (isset($args['size']) && ($args['size'] = 'small')) {
        echo "</a>";
    }
    ?>

  </td>
  <td align="right" width="1%" nowrap><?php 
    if (!isset($args['size']) || $args['size'] != 'small') {
        template_get_next_calendar($args);
    }
    ?>
 </td>
  </tr>
  </table>
</td>
</tr>
<tr>
<td class="monthCalBody">
<?php 
    if ($args['calendar']->view == 'month') {
        template_calendar_month($args);
    } else {
        if ($args['calendar']->view == 'year') {
            template_calendar_year($args);
        } else {
            if ($args['calendar']->view == 'shared') {
                global $current_user, $shared_user;
                $shared_args = array();
                foreach ($args as $key => $val) {
                    $shared_args[$key] = $val;
                }
                $shared_args['calendar'] = $args['calendar'];
                $shared_user = new User();
                foreach ($ids as $member) {
                    $shared_user->retrieve($member);
                    $shared_args['calendar']->show_tasks = true;
                    $shared_args['calendar']->add_activities($shared_user);
                    $shared_args['show_link'] = 'off';
                    if ($shared_user->id == $current_user->id) {
                        $shared_args['show_link'] = 'on';
                    }
                    echo '<h5 class="calSharedUser">' . $shared_user->full_name . '</h5>';
                    template_calendar_horizontal($shared_args);
                }
            } else {
                template_calendar_vertical($args);
            }
        }
    }
    ?>
</td>
</tr>
<tr>
<td>
  <table width="100%" cellspacing="0" cellpadding="0" class="monthFooter">
  <tr>
  <td width="50%"><?php 
    template_get_previous_calendar($args);
    ?>
</td>
  <td align="right" width="50%"><?php 
    template_get_next_calendar($args);
    ?>
</td>
  </tr>
  </table>

</td>
</tr>
</table>
<?php 
}
 function set_record(SugarBean $record, SugarBean $bean, $params = array(), $in_save = false)
 {
     global $app_list_strings, $timedate;
     $record_vardefs = $record->getFieldDefinitions();
     if (isset($params['field'])) {
         foreach ($params['field'] as $key => $field) {
             if ($field == '') {
                 continue;
             }
             switch ($params['value_type'][$key]) {
                 case 'Field':
                     if ($params['value'][$key] == '') {
                         continue;
                     }
                     $data = $bean->field_defs[$params['value'][$key]];
                     if ($data['type'] == 'relate' && isset($data['id_name'])) {
                         $params['value'][$key] = $data['id_name'];
                     }
                     $value = $bean->{$params}['value'][$key];
                     break;
                 case 'Date':
                     $dformat = 'Y-m-d H:i:s';
                     if ($record_vardefs[$field]['type'] == 'date') {
                         $dformat = 'Y-m-d';
                     }
                     switch ($params['value'][$key][3]) {
                         case 'business_hours':
                             if (file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')) {
                                 require_once 'modules/AOBH_BusinessHours/AOBH_BusinessHours.php';
                                 $businessHours = new AOBH_BusinessHours();
                                 $dateToUse = $params['value'][$key][0];
                                 $sign = $params['value'][$key][1];
                                 $amount = $params['value'][$key][2];
                                 if ($sign != "plus") {
                                     $amount = 0 - $amount;
                                 }
                                 if ($dateToUse == "now") {
                                     $value = $businessHours->addBusinessHours($amount);
                                 } else {
                                     if ($dateToUse == "field") {
                                         $dateToUse = $params['field'][$key];
                                         $value = $businessHours->addBusinessHours($amount, $timedate->fromDb($bean->{$dateToUse}));
                                     } else {
                                         $value = $businessHours->addBusinessHours($amount, $timedate->fromDb($bean->{$dateToUse}));
                                     }
                                 }
                                 $value = $timedate->asDb($value);
                                 break;
                             }
                             $params['value'][$key][3] = 'hours';
                             //No business hours module found - fall through.
                         //No business hours module found - fall through.
                         default:
                             if ($params['value'][$key][0] == 'now') {
                                 $date = gmdate($dformat);
                             } else {
                                 if ($params['value'][$key][0] == 'field') {
                                     $date = $record->fetched_row[$params['field'][$key]];
                                 } else {
                                     $date = $bean->fetched_row[$params['value'][$key][0]];
                                 }
                             }
                             if ($params['value'][$key][1] != 'now') {
                                 $value = date($dformat, strtotime($date . ' ' . $app_list_strings['aow_date_operator'][$params['value'][$key][1]] . $params['value'][$key][2] . ' ' . $params['value'][$key][3]));
                             } else {
                                 $value = date($dformat, strtotime($date));
                             }
                             break;
                     }
                     break;
                 case 'Round_Robin':
                 case 'Least_Busy':
                 case 'Random':
                     switch ($params['value'][$key][0]) {
                         case 'security_group':
                             if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
                                 require_once 'modules/SecurityGroups/SecurityGroup.php';
                                 $security_group = new SecurityGroup();
                                 $security_group->retrieve($params['value'][$key][1]);
                                 $group_users = $security_group->get_linked_beans('users', 'User');
                                 $users = array();
                                 $r_users = array();
                                 if ($params['value'][$key][2] != '') {
                                     require_once 'modules/ACLRoles/ACLRole.php';
                                     $role = new ACLRole();
                                     $role->retrieve($params['value'][$key][2]);
                                     $role_users = $role->get_linked_beans('users', 'User');
                                     foreach ($role_users as $role_user) {
                                         $r_users[$role_user->id] = $role_user->name;
                                     }
                                 }
                                 foreach ($group_users as $group_user) {
                                     if ($params['value'][$key][2] != '' && !isset($r_users[$group_user->id])) {
                                         continue;
                                     }
                                     $users[$group_user->id] = $group_user->name;
                                 }
                                 break;
                             }
                             //No Security Group module found - fall through.
                         //No Security Group module found - fall through.
                         case 'role':
                             require_once 'modules/ACLRoles/ACLRole.php';
                             $role = new ACLRole();
                             $role->retrieve($params['value'][$key][2]);
                             $role_users = $role->get_linked_beans('users', 'User');
                             $users = array();
                             foreach ($role_users as $role_user) {
                                 $users[$role_user->id] = $role_user->name;
                             }
                             break;
                         case 'all':
                         default:
                             $users = get_user_array(false);
                             break;
                     }
                     // format the users array
                     $users = array_values(array_flip($users));
                     if (empty($users)) {
                         $value = '';
                     } else {
                         if (sizeof($users) == 1) {
                             $value = $users[0];
                         } else {
                             switch ($params['value_type'][$key]) {
                                 case 'Round_Robin':
                                     $value = getRoundRobinUser($users, $this->id);
                                     break;
                                 case 'Least_Busy':
                                     $user_id = 'assigned_user_id';
                                     if (isset($record_vardefs[$field]['id_name']) && $record_vardefs[$field]['id_name'] != '') {
                                         $user_id = $record_vardefs[$field]['id_name'];
                                     }
                                     $value = getLeastBusyUser($users, $user_id, $record);
                                     break;
                                 case 'Random':
                                 default:
                                     shuffle($users);
                                     $value = $users[0];
                                     break;
                             }
                         }
                     }
                     setLastUser($value, $this->id);
                     break;
                 case 'Value':
                 default:
                     $value = $params['value'][$key];
                     break;
             }
             if ($record_vardefs[$field]['type'] == 'relate' && isset($record_vardefs[$field]['id_name'])) {
                 $field = $record_vardefs[$field]['id_name'];
             }
             $record->{$field} = $value;
         }
     }
     $bean_processed = isset($record->processed) ? $record->processed : false;
     if ($in_save) {
         global $current_user;
         $record->processed = true;
         $check_notify = $record->assigned_user_id != $current_user->id && $record->assigned_user_id != $record->fetched_row['assigned_user_id'];
     } else {
         $check_notify = $record->assigned_user_id != $record->fetched_row['assigned_user_id'];
     }
     $record->process_save_dates = false;
     $record->new_with_id = false;
     $record->save($check_notify);
     $record->processed = $bean_processed;
 }
 private function getEmailsFromParams(SugarBean $bean, $params)
 {
     $emails = array();
     //backward compatible
     if (isset($params['email_target_type']) && !is_array($params['email_target_type'])) {
         $email = '';
         switch ($params['email_target_type']) {
             case 'Email Address':
                 $params['email'] = array($params['email']);
                 break;
             case 'Specify User':
                 $params['email'] = array($params['email_user_id']);
                 break;
             case 'Related Field':
                 $params['email'] = array($params['email_target']);
                 break;
         }
         $params['email_target_type'] = array($params['email_target_type']);
         $params['email_to_type'] = array('to');
     }
     //end backward compatible
     if (isset($params['email_target_type'])) {
         foreach ($params['email_target_type'] as $key => $field) {
             switch ($field) {
                 case 'Email Address':
                     if (trim($params['email'][$key]) != '') {
                         $emails[$params['email_to_type'][$key]][] = $params['email'][$key];
                     }
                     break;
                 case 'Specify User':
                     $user = new User();
                     $user->retrieve($params['email'][$key]);
                     $user_email = $user->emailAddress->getPrimaryAddress($user);
                     if (trim($user_email) != '') {
                         $emails[$params['email_to_type'][$key]][] = $user_email;
                         $emails['template_override'][$user_email] = array('Users' => $user->id);
                     }
                     break;
                 case 'Users':
                     $users = array();
                     switch ($params['email'][$key][0]) {
                         case 'security_group':
                             if (file_exists('modules/SecurityGroups/SecurityGroup.php')) {
                                 require_once 'modules/SecurityGroups/SecurityGroup.php';
                                 $security_group = new SecurityGroup();
                                 $security_group->retrieve($params['email'][$key][1]);
                                 $users = $security_group->get_linked_beans('users', 'User');
                                 $r_users = array();
                                 if ($params['email'][$key][2] != '') {
                                     require_once 'modules/ACLRoles/ACLRole.php';
                                     $role = new ACLRole();
                                     $role->retrieve($params['email'][$key][2]);
                                     $role_users = $role->get_linked_beans('users', 'User');
                                     foreach ($role_users as $role_user) {
                                         $r_users[$role_user->id] = $role_user->name;
                                     }
                                 }
                                 foreach ($users as $user_id => $user) {
                                     if ($params['email'][$key][2] != '' && !isset($r_users[$user->id])) {
                                         unset($users[$user_id]);
                                     }
                                 }
                                 break;
                             }
                             //No Security Group module found - fall through.
                         //No Security Group module found - fall through.
                         case 'role':
                             require_once 'modules/ACLRoles/ACLRole.php';
                             $role = new ACLRole();
                             $role->retrieve($params['email'][$key][2]);
                             $users = $role->get_linked_beans('users', 'User');
                             break;
                         case 'all':
                         default:
                             global $db;
                             $sql = "SELECT id from users WHERE status='Active' AND portal_only=0 ";
                             $result = $db->query($sql);
                             while ($row = $db->fetchByAssoc($result)) {
                                 $user = new User();
                                 $user->retrieve($row['id']);
                                 $users[$user->id] = $user;
                             }
                             break;
                     }
                     foreach ($users as $user) {
                         $user_email = $user->emailAddress->getPrimaryAddress($user);
                         if (trim($user_email) != '') {
                             $emails[$params['email_to_type'][$key]][] = $user_email;
                             $emails['template_override'][$user_email] = array('Users' => $user->id);
                         }
                     }
                     break;
                 case 'Related Field':
                     $emailTarget = $params['email'][$key];
                     $relatedFields = array_merge($bean->get_related_fields(), $bean->get_linked_fields());
                     $field = $relatedFields[$emailTarget];
                     if ($field['type'] == 'relate') {
                         $linkedBeans = array();
                         $idName = $field['id_name'];
                         $id = $bean->{$idName};
                         $linkedBeans[] = BeanFactory::getBean($field['module'], $id);
                     } else {
                         if ($field['type'] == 'link') {
                             $relField = $field['name'];
                             if (isset($field['module']) && $field['module'] != '') {
                                 $rel_module = $field['module'];
                             } else {
                                 if ($bean->load_relationship($relField)) {
                                     $rel_module = $bean->{$relField}->getRelatedModuleName();
                                 }
                             }
                             $linkedBeans = $bean->get_linked_beans($relField, $rel_module);
                         } else {
                             $linkedBeans = $bean->get_linked_beans($field['link'], $field['module']);
                         }
                     }
                     if ($linkedBeans) {
                         foreach ($linkedBeans as $linkedBean) {
                             $rel_email = $linkedBean->emailAddress->getPrimaryAddress($linkedBean);
                             if (trim($rel_email) != '') {
                                 $emails[$params['email_to_type'][$key]][] = $rel_email;
                                 $emails['template_override'][$rel_email] = array($linkedBean->module_dir => $linkedBean->id);
                             }
                         }
                     }
                     break;
                 case 'Record Email':
                     $recordEmail = $bean->emailAddress->getPrimaryAddress($bean);
                     if ($recordEmail == '' && isset($bean->email1)) {
                         $recordEmail = $bean->email1;
                     }
                     if (trim($recordEmail) != '') {
                         $emails[$params['email_to_type'][$key]][] = $recordEmail;
                     }
                     break;
             }
         }
     }
     return $emails;
 }
Exemple #11
0
global $current_user, $db;
$module = $_REQUEST['return_module'];
$sugarbean = null;
$securitygroup = $_REQUEST['massassign_group'];
if (!isset($module) || empty($securitygroup) || !isset($securitygroup)) {
    return;
}
if (!empty($GLOBALS['beanList'][$module])) {
    $class = $GLOBALS['beanList'][$module];
    if (!empty($GLOBALS['beanFiles'][$class])) {
        require_once $GLOBALS['beanFiles'][$class];
        $sugarbean = new $class();
    }
}
$groupFocus = new SecurityGroup();
$groupFocus->retrieve($securitygroup);
if (!empty($_REQUEST['uid'])) {
    $_POST['mass'] = explode(',', $_REQUEST['uid']);
} elseif (isset($_REQUEST['entire'])) {
    if (isset($_SESSION['export_where']) && !empty($_SESSION['export_where'])) {
        // bug 4679
        $where = $_SESSION['export_where'];
        $whereArr = explode(" ", trim($where));
        if ($whereArr[0] == trim('where')) {
            $whereClean = array_shift($whereArr);
        }
        $where = implode(" ", $whereArr);
    } else {
        $where = '';
    }
    if (empty($order_by)) {
 function deleteMessage()
 {
     if (!empty($_REQUEST['record'])) {
         $message = new SecurityGroupMessage();
         $message->retrieve($_REQUEST['record']);
         $group_owner = false;
         if (!empty($message->securitygroup_id)) {
             require_once 'modules/SecurityGroups/SecurityGroup.php';
             $securitygroup = new SecurityGroup();
             $securitygroup->retrieve($data['SECURITYGROUP_ID']);
             if ($securitygroup->assigned_user_id == $GLOBALS['current_user']->id) {
                 $group_owner = true;
             }
         }
         //change all logic like below to check if assigned user to security group as well...
         if (is_admin($GLOBALS['current_user']) || $message->created_by == $GLOBALS['current_user']->id || $group_owner) {
             $message->mark_deleted($_REQUEST['record']);
         }
     }
 }
Exemple #13
0
 function processStudio($ajax)
 {
     $this->ajax->addCrumb(translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")');
     if (!isset($this->editModule)) {
         //Studio Select Module Page
         $this->generateStudioModuleButtons();
         $this->question = translate('LBL_QUESTION_EDIT');
         $this->title = translate('LBL_STUDIO');
         global $current_user;
         if (is_admin($current_user)) {
             $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=exportcustomizations');\" value=\"" . translate('LBL_BTN_EXPORT') . '">';
         }
         $this->help = 'studioHelp';
     } else {
         $module = StudioModuleFactory::getStudioModule($this->editModule);
         $this->ajax->addCrumb($module->name, !empty($this->view) ? 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' : '');
         switch ($this->view) {
             case 'layouts':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 //Studio Select Layout page
                 $this->buttons = $module->getLayouts();
                 $this->title = $module->name . " " . translate('LBL_LAYOUTS');
                 $this->question = translate('LBL_QUESTION_LAYOUT');
                 $this->help = 'layoutsHelp';
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), '');
                 break;
             case 'subpanels':
                 //Studio Select Subpanel page.
                 $this->buttons = $module->getSubpanels();
                 $this->title = $module->name . " " . translate('LBL_SUBPANELS');
                 $this->question = translate('LBL_QUESTION_SUBPANEL');
                 $this->ajax->addCrumb(translate('LBL_SUBPANELS'), '');
                 $this->help = 'subpanelHelp';
                 break;
             case 'search':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 //Studio Select Search Layout page.
                 $this->buttons = $module->getSearch();
                 $this->title = $module->name . " " . translate('LBL_SEARCH');
                 $this->question = translate('LBL_QUESTION_SEARCH');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_SEARCH'), '');
                 $this->help = 'searchHelp';
                 break;
             case 'dashlet':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 $this->generateStudioDashletButtons();
                 $this->title = $this->editModule . " " . translate('LBL_DASHLET');
                 $this->question = translate('LBL_QUESTION_DASHLET');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_DASHLET'), '');
                 $this->help = 'dashletHelp';
                 break;
             case 'popup':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 $this->generateStudioPopupButtons();
                 $this->title = $this->editModule . " " . translate('LBL_POPUP');
                 $this->question = translate('LBL_QUESTION_POPUP');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_POPUP'), '');
                 $this->help = 'popupHelp';
                 break;
             default:
                 //Studio Edit Module Page
                 $this->buttons = $module->getModule();
                 $this->question = translate('LBL_QUESTION_MODULE');
                 $this->title = translate('LBL_EDIT') . " " . $module->name;
                 $this->help = 'moduleHelp';
                 global $current_user;
                 if (is_admin($current_user)) {
                     $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" " . "onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=resetmodule&view_module={$this->editModule}');\" value=\"" . "Reset Module" . '">';
                 }
         }
     }
 }