/** gives the role info, role profile info and role user info details in an array  for the specified role id
 * @param $roleid -- role id:: Type integer
 * @returns $return_data -- array contains role info, role profile info and role user info. This array is used to construct the detail view for the specified role id :: Type varchar
 *
 */
function getStdOutput($roleid)
{
    //Retreiving the related vtiger_profiles
    $roleProfileArr = getRoleRelatedProfiles($roleid);
    //Retreving the related vtiger_users
    $roleUserArr = getRoleUsers($roleid);
    //Constructing the Profile list
    $profileinfo = array();
    foreach ($roleProfileArr as $profileId => $profileName) {
        $profileinfo[] = $profileId;
        $profileinfo[] = $profileName;
        $profileList .= '<a href="index.php?module=Settings&action=profilePrivileges&profileid=' . $profileId . '">' . $profileName . '</a>';
    }
    $profileinfo = array_chunk($profileinfo, 2);
    //Constructing the Users List
    $userinfo = array();
    foreach ($roleUserArr as $userId => $userName) {
        $userinfo[] = $userId;
        $userinfo[] = $userName;
        $userList .= '<a href="index.php?module=Settings&action=DetailView&record=' . $userId . '">' . $userName . '</a>';
    }
    $userinfo = array_chunk($userinfo, 2);
    //Check for Current User
    global $current_user;
    $current_role = fetchUserRole($current_user->id);
    $return_data = array('profileinfo' => $profileinfo, 'userinfo' => $userinfo);
    return $return_data;
}
Example #2
0
	public function getRecipientEmails() {
		$recipientsInfo = $this->scheduledRecipients;

		$recipientsList = array();
		if(!empty($recipientsInfo)) {
			if(!empty($recipientsInfo['users'])) {
				$recipientsList = array_merge($recipientsList, $recipientsInfo['users']);
			}

			if(!empty($recipientsInfo['roles'])) {
				foreach($recipientsInfo['roles'] as $roleId) {
					$roleUsers = getRoleUsers($roleId);
					foreach($roleUsers as $userId => $userName) {
						array_push($recipientsList, $userId);
					}
				}
			}

			if(!empty($recipientsInfo['rs'])) {
				foreach($recipientsInfo['rs'] as $roleId) {
					$users = getRoleAndSubordinateUsers($roleId);
					foreach($users as $userId => $userName) {
						array_push($recipientsList, $userId);
					}
				}
			}


			if(!empty($recipientsInfo['groups'])) {
				require_once 'include/utils/GetGroupUsers.php';
				foreach($recipientsInfo['groups'] as $groupId) {
					$userGroups = new GetGroupUsers();
					$userGroups->getAllUsersInGroup($groupId);
					$recipientsList = array_merge($recipientsList, $userGroups->group_users);
				}
			}
		}
		$recipientsEmails = array();
		if(!empty($recipientsList) && count($recipientsList) > 0) {
			foreach($recipientsList as $userId) {
				$userName = getUserFullName($userId);
				$userEmail = getUserEmail($userId);
				if(!in_array($userEmail, $recipientsEmails)) {
					$recipientsEmails[$userName] = $userEmail;
				}
			}
		}
		return $recipientsEmails;
	}
Example #3
0
 public function getRecipientEmails()
 {
     $recipientsInfo = $this->get('recipients');
     if (!empty($recipientsInfo)) {
         $recipients = array();
         $recipientsInfo = Zend_Json::decode($recipientsInfo);
         foreach ($recipientsInfo as $key => $recipient) {
             if (strpos($recipient, 'USER') !== false) {
                 $id = explode('::', $recipient);
                 $recipients['Users'][] = $id[1];
             } else {
                 if (strpos($recipient, 'GROUP') !== false) {
                     $id = explode('::', $recipient);
                     $recipients['Groups'][] = $id[1];
                 } else {
                     if (strpos($recipient, 'ROLE') !== false) {
                         $id = explode('::', $recipient);
                         $recipients['Roles'][] = $id[1];
                     }
                 }
             }
         }
     }
     $recipientsList = array();
     if (!empty($recipients)) {
         if (!empty($recipients['Users'])) {
             $recipientsList = array_merge($recipientsList, $recipients['Users']);
         }
         if (!empty($recipients['Roles'])) {
             foreach ($recipients['Roles'] as $roleId) {
                 $roleUsers = getRoleUsers($roleId);
                 foreach ($roleUsers as $userId => $userName) {
                     array_push($recipientsList, $userId);
                 }
             }
         }
         if (!empty($recipients['Groups'])) {
             require_once 'include/utils/GetGroupUsers.php';
             foreach ($recipients['Groups'] as $groupId) {
                 $userGroups = new GetGroupUsers();
                 $userGroups->getAllUsersInGroup($groupId);
                 $recipientsList = array_merge($recipientsList, $userGroups->group_users);
             }
         }
     }
     $recipientsList = array_unique($recipientsList);
     $recipientsEmails = array();
     if (!empty($recipientsList) && count($recipientsList) > 0) {
         foreach ($recipientsList as $userId) {
             if (!Vtiger_Util_Helper::isUserDeleted($userId)) {
                 $userName = getUserFullName($userId);
                 $userEmail = getUserEmail($userId);
                 if (!in_array($userEmail, $recipientsEmails)) {
                     $recipientsEmails[$userName] = $userEmail;
                 }
             }
         }
     }
     //Added for specific email address.
     $specificemails = explode(',', Zend_Json::decode($this->get('specificemails')));
     if (!empty($specificemails)) {
         $recipientsEmails = array_merge($recipientsEmails, $specificemails);
     }
     return $recipientsEmails;
 }
Example #4
0
/** To retreive the subordinate vtiger_roles and vtiger_users of the specified parent vtiger_role
 * @param $roleid -- The Role Id:: Type varchar
 * @returns  subordinate vtiger_role array in the following format:
 *     $subordinateRoleUserArray=(roleid1=>Array(userid1,userid2,userid3),
  vtiger_roleid2=>Array(userid1,userid2,userid3)
  |
  |
  vtiger_roleidn=>Array(userid1,userid2,userid3));
 */
function getSubordinateRoleAndUsers($roleId)
{
    $log = vglobal('log');
    $log->debug("Entering getSubordinateRoleAndUsers(" . $roleId . ") method ...");
    $adb = PearDatabase::getInstance();
    $subRoleAndUsers = array();
    $subordinateRoles = getRoleSubordinates($roleId);
    foreach ($subordinateRoles as $subRoleId) {
        $userArray = getRoleUsers($subRoleId);
        $subRoleAndUsers[$subRoleId] = $userArray;
    }
    $log->debug("Exiting getSubordinateRoleAndUsers method ...");
    return $subRoleAndUsers;
}
Example #5
0
/** To retreive the subordinate vtiger_roles and vtiger_users of the specified parent vtiger_role
  * @param $roleid -- The Role Id:: Type varchar
  * @returns  subordinate vtiger_role array in the following format:
  *     $subordinateRoleUserArray=(roleid1=>Array(userid1,userid2,userid3),
                               vtiger_roleid2=>Array(userid1,userid2,userid3)
				                |
						|
			       vtiger_roleidn=>Array(userid1,userid2,userid3));
 */
function getSubordinateRoleAndUsers($roleId, $users = true)
{
    global $log;
    $log->debug("Entering getSubordinateRoleAndUsers(" . $roleId . ") method ...");
    global $adb;
    $subRoleAndUsers = array();
    $subordinateRoles = getRoleSubordinates($roleId);
    $userArray = array();
    foreach ($subordinateRoles as $subRoleId) {
        if ($users) {
            $userArray = getRoleUsers($subRoleId);
        }
        $subRoleAndUsers[$subRoleId] = $userArray;
    }
    $log->debug("Exiting getSubordinateRoleAndUsers method ...");
    return $subRoleAndUsers;
}
Example #6
0
 /** to get all the vtiger_users and vtiger_groups of the specified group
  * @params $groupId --> Group Id :: Type Integer
  * @returns the vtiger_users present in the group in the variable $parent_groups of the class
  * @returns the sub vtiger_groups present in the group in the variable $group_subgroups of the class
  */
 function getAllUsersInGroup($groupid)
 {
     $adb = PearDatabase::getInstance();
     $log = vglobal('log');
     $log->debug("Entering getAllUsersInGroup(" . $groupid . ") method...");
     //Retreiving from the user2grouptable
     $query = "select * from vtiger_users2group where groupid=?";
     $result = $adb->pquery($query, array($groupid));
     $num_rows = $adb->num_rows($result);
     for ($i = 0; $i < $num_rows; $i++) {
         $now_user_id = $adb->query_result($result, $i, 'userid');
         if (!in_array($now_user_id, $this->group_users)) {
             $this->group_users[] = $now_user_id;
         }
     }
     //Retreiving from the vtiger_group2role
     $query = "select * from vtiger_group2role where groupid=?";
     $result = $adb->pquery($query, array($groupid));
     $num_rows = $adb->num_rows($result);
     for ($i = 0; $i < $num_rows; $i++) {
         $now_role_id = $adb->query_result($result, $i, 'roleid');
         $now_role_users = array();
         $now_role_users = getRoleUsers($now_role_id);
         foreach ($now_role_users as $now_role_userid => $now_role_username) {
             if (!in_array($now_role_userid, $this->group_users)) {
                 $this->group_users[] = $now_role_userid;
             }
         }
     }
     //Retreiving from the vtiger_group2rs
     $query = "select * from vtiger_group2rs where groupid=?";
     $result = $adb->pquery($query, array($groupid));
     $num_rows = $adb->num_rows($result);
     for ($i = 0; $i < $num_rows; $i++) {
         $now_rs_id = $adb->query_result($result, $i, 'roleandsubid');
         $now_rs_users = getRoleAndSubordinateUsers($now_rs_id);
         foreach ($now_rs_users as $now_rs_userid => $now_rs_username) {
             if (!in_array($now_rs_userid, $this->group_users)) {
                 $this->group_users[] = $now_rs_userid;
             }
         }
     }
     //Retreving from group2group
     $query = "select * from vtiger_group2grouprel where groupid=?";
     $result = $adb->pquery($query, array($groupid));
     $num_rows = $adb->num_rows($result);
     for ($i = 0; $i < $num_rows; $i++) {
         $now_grp_id = $adb->query_result($result, $i, 'containsgroupid');
         $focus = new GetGroupUsers();
         $focus->getAllUsersInGroup($now_grp_id);
         $now_grp_users = $focus->group_users;
         $now_grp_grps = $focus->group_subgroups;
         if (!array_key_exists($now_grp_id, $this->group_subgroups)) {
             $this->group_subgroups[$now_grp_id] = $now_grp_users;
         }
         foreach ($focus->group_users as $temp_user_id) {
             if (!in_array($temp_user_id, $this->group_users)) {
                 $this->group_users[] = $temp_user_id;
             }
         }
         foreach ($focus->group_subgroups as $temp_grp_id => $users_array) {
             if (!array_key_exists($temp_grp_id, $this->group_subgroups)) {
                 $this->group_subgroups[$temp_grp_id] = $focus->group_users;
             }
         }
     }
     $log->debug("Exiting getAllUsersInGroup method...");
 }
Example #7
0
 /**
  * @param $context \Workflow\VTEntity
  */
 public function handleTask(&$context)
 {
     global $current_user, $adb;
     if ($this->isContinued()) {
         $sql = "SELECT id, result, result_user_id FROM vtiger_wf_confirmation WHERE execID = '" . $this->getExecId() . "' AND result != '' AND visible = 1";
         $result = $adb->query($sql);
         if ($adb->num_rows($result) == 0) {
             $timeout = $context->getEnvironment('_permissionTimeout');
             $timeoutValue = $context->getEnvironment('_permissionTimeoutValue');
             if ($timeout == true) {
                 if (time() > $timeoutValue) {
                     $this->addStat('Timeout action: ' . $this->get('timeout_output'));
                     return $this->get('timeout_output');
                 }
             }
             return array("delay" => time() + 60 * 10, "checkmode" => "static");
         }
         $data = $adb->fetchByAssoc($result);
         $sql = "SELECT user_name FROM vtiger_users WHERE id = " . $data["result_user_id"];
         $resultUser = $adb->query($sql);
         $resultUser = $adb->fetchByAssoc($resultUser);
         $this->addStat("Permission: " . $data["result"] . " by " . $resultUser["user_name"]);
         $sql = "UPDATE vtiger_wf_confirmation SET visible = 0 WHERE id = " . $data["id"];
         $adb->query($sql);
         return $data["result"];
     }
     $this->_compatible();
     $connected = $this->getConnectedObjects("assigned_to");
     $targets = array();
     if (!empty($connected)) {
         foreach ($connected as $user) {
             if (empty($user)) {
                 continue;
             }
             $targets['user'][] = intval($user->getId());
         }
     }
     $TMPtargets = $this->get('targets');
     if (is_array($TMPtargets)) {
         foreach ($TMPtargets as $value) {
             $parts = explode('##', $value);
             if ($parts[0] == 'USER' && !in_array(intval($parts[1]), $targets['user'])) {
                 $targets['user'][] = intval($parts[1]);
             }
             if ($parts[0] == 'GROUP') {
                 $focusGrpUsers = new GetGroupUsers();
                 $focusGrpUsers->getAllUsersInGroup($parts[1]);
                 $groupUser = $focusGrpUsers->group_users;
                 if (is_array($groupUser)) {
                     foreach ($groupUser as $userId) {
                         if (!in_array($userId, $targets['user'])) {
                             $targets['user'][] = $userId;
                         }
                     }
                 }
             }
             if ($parts[0] == 'ROLE') {
                 $focusGrpUsers = new GetGroupUsers();
                 $focusGrpUsers->getAllUsersInGroup($parts[0]);
                 $groupUser = array_keys(getRoleUsers($parts[1]));
                 if (is_array($groupUser)) {
                     foreach ($groupUser as $userId) {
                         if (!in_array($userId, $targets['user'])) {
                             $targets['user'][] = $userId;
                         }
                     }
                 }
             }
         }
     }
     $backgroundcolor = $this->get("backgroundcolor");
     $bgmode = $this->get("bgmode");
     if (!empty($bgmode) && $bgmode != -1) {
         if ($bgmode == "function") {
             $parser = new VTWfExpressionParser($backgroundcolorFKT, $context, false);
             # Last Parameter = DEBUG
             try {
                 $parser->run();
             } catch (ExpressionException $exp) {
                 Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
             }
             $backgroundcolor = $parser->getReturn();
         } else {
             if (strpos($backgroundcolor, '$') !== false || strpos($backgroundcolor, '?') !== false) {
                 $objTemplate = new VTTemplate($context);
                 $backgroundcolor = $objTemplate->render($backgroundcolor);
             }
         }
     } else {
         $backgroundcolor = "#ffffff";
     }
     if (empty($backgroundcolor)) {
         $backgroundcolor = "#ffffff";
     }
     $infomessage = $this->get("infomessage");
     $infomessageFKT = $this->get("infomessageFKT");
     $infomode = $this->get("infomode");
     if (!empty($infomode) && $infomode != -1) {
         if ($infomode == "function") {
             $parser = new VTWfExpressionParser($infomessageFKT, $context, false);
             # Last Parameter = DEBUG
             try {
                 $parser->run();
             } catch (ExpressionException $exp) {
                 Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
             }
             $infomessage = $parser->getReturn();
         } else {
             if (strpos($infomessage, '$') !== false || strpos($infomessage, '?') !== false) {
                 $objTemplate = new VTTemplate($context);
                 $infomessage = $objTemplate->render($infomessage);
             }
         }
     } else {
         $infomessage = "";
     }
     if (empty($infomessage)) {
         $infomessage = "";
     }
     $rundirect = $this->get("rundirect");
     $sql = "INSERT INTO vtiger_wf_confirmation SET crmid = " . $context->getId() . ", infomessage = ?, backgroundcolor = ?, blockID = '" . $this->getBlockId() . "', execID = '" . $this->getExecId() . "', visible = 1, result = '', module = '" . $context->getModuleName() . "', workflow_id = " . $this->getWorkflowId() . ", rundirect = " . ($rundirect == "1" ? 1 : 0) . ", from_user_id = " . $current_user->id;
     $adb->pquery($sql, array($infomessage, $backgroundcolor));
     $confID = $adb->getLastInsertID();
     foreach ($targets['user'] as $user) {
         $sql = "INSERT INTO vtiger_wf_confirmation_user SET confirmation_id = '" . $confID . "', user_id = " . $user;
         $adb->query($sql);
         $this->addStat("create Permission entry (Block " . $this->getBlockId() . ") for User " . $user);
     }
     // if we need an timeout than wait until
     $use_timeout = $this->get("use_timeout");
     if ($use_timeout == '1') {
         $timeout_value = $this->get("timeout_value");
         $timeout_value_mode = $this->get("timeout_value_mode");
         $timestamp = time();
         switch ($timeout_value_mode) {
             case "minutes":
                 $timestamp += 60 * $timeout_value;
                 break;
             case "hours":
                 $timestamp += 60 * 60 * $timeout_value;
                 break;
             case "days":
                 $timestamp += 24 * 60 * 60 * $timeout_value;
                 break;
             case "weeks":
                 $timestamp += 7 * 24 * 60 * 60 * $timeout_value;
                 break;
         }
         $context->setEnvironment('_permissionTimeout', true);
         $context->setEnvironment('_permissionTimeoutValue', $timestamp);
     } else {
         $context->setEnvironment('_permissionTimeout', false);
     }
     // check every 15 minutes
     return array("delay" => time() + 60 * 15, "checkmode" => "static");
 }
Example #8
0
                                            </div>
                                            <div class="col-lg-3" style="padding-left: 40px;">
                                                <button class='btn btn-success btn-sm personOK inline'>
                                                    <span class='glyphicon glyphicon-ok' aria-hidden='true'></span>
                                                </button>
                                                <button class='btn btn-success btn-sm personADD inline'>
                                                    <span class='glyphicon glyphicon-plus' aria-hidden='true'></span>
                                                </button>
                                            </div>
                                        </li>
                                        <li class="list-group-item">
                                            <h5 class="list-group-item-heading">5. <i class="glyphicon glyphicon-user" aria-hidden="true"></i> General director</h5>
                                            <div class="col-lg-9">
                                                <select class="selectpicker" data-width="100%">
                                                    <?php 
echo getRoleUsers(1);
?>
                                                </select>
                                            </div>
                                            <div class="col-lg-3" style="padding-left: 40px;">
                                                <button class='btn btn-success btn-sm personOK inline'>
                                                    <span class='glyphicon glyphicon-ok' aria-hidden='true'></span>
                                                </button>
                                                <button class='btn btn-success btn-sm personADD inline'>
                                                    <span class='glyphicon glyphicon-plus' aria-hidden='true'></span>
                                                </button>
                                            </div>
                                        </li>
                                    </ul>
                                    <div class="col-lg-12">
                                        <button type="submit" id="createpurch" class="btn btn-success disabled" style="width:100%; margin-bottom: 15px;">Create application for purchase</button>