public function DisplaySearchForm($sClass, $aAttList, $aExtraParams, $sPrefix, $bClosed = true) { $oUserOrg = $this->GetUserOrg(); $aFilterParams = array('org_id' => $oUserOrg->GetKey(), 'contact_id' => UserRights::GetContactId()); $sCSSClass = $bClosed ? 'DrawerClosed' : ''; $this->add("<div id=\"ds_{$sPrefix}\" class=\"SearchDrawer {$sCSSClass}\">\n"); $this->add_ready_script(<<<EOF \t\t\$("#dh_{$sPrefix}").click( function() { \t\t\$("#ds_{$sPrefix}").slideToggle('normal', function() { \$("#ds_{$sPrefix}").parent().resize(); } ); \t\t\$("#dh_{$sPrefix}").toggleClass('open'); \t}); EOF ); $this->add("<form id=\"search_{$sClass}\" action=\"\" method=\"post\">\n"); // Don't use $_SERVER['SCRIPT_NAME'] since the form may be called asynchronously (from ajax.php) // $this->add("<h2>".Dict::Format('UI:SearchFor_Class_Objects', 'xxxxxx')."</h2>\n"); $this->add("<p>\n"); foreach ($aAttList as $sAttSpec) { //$oAppContext->Reset($sAttSpec); // Make sure the same parameter will not be passed twice $this->DisplaySearchField($sClass, $sAttSpec, $aExtraParams, $sPrefix, null, $aFilterParams); } $this->add("</p>\n"); $this->add("<p align=\"right\"><input type=\"submit\" value=\"" . Dict::S('UI:Button:Search') . "\"></p>\n"); foreach ($aExtraParams as $sName => $sValue) { // Note: use DumpHiddenParams() to transmit arrays as hidden params if (is_scalar($sValue)) { $this->add("<input type=\"hidden\" name=\"{$sName}\" value=\"{$sValue}\" />\n"); } } // $this->add($oAppContext->GetForForm()); $this->add("</form>\n"); $this->add("</div>\n"); $this->add("<div class=\"HRDrawer\"></div>\n"); $this->add("<div id=\"dh_{$sPrefix}\" class=\"DrawerHandle\">" . Dict::S('UI:SearchToggle') . "</div>\n"); }
/** * Get The organization of the current user (i.e. the organization of its contact) * @param WebPage $oP The current page, for errors output * @return Organization The user's org or null in case of problem... */ function GetUserOrg() { $oOrg = null; $iContactId = UserRights::GetContactId(); $oContact = MetaModel::GetObject('Contact', $iContactId, false); // false => Can fail if (is_object($oContact)) { $oOrg = MetaModel::GetObject('Organization', $oContact->Get('org_id'), false); // false => can fail } else { throw new Exception(Dict::S('Portal:ErrorNoContactForThisUser')); } return $oOrg; }
protected function ExpandArgs() { $aScalarArgs = $this->m_oFilter->GetInternalParams(); foreach ($this->m_aArgs as $sArgName => $value) { if (MetaModel::IsValidObject($value)) { if (strpos($sArgName, '->object()') === false) { // Lazy syntax - develop the object contextual parameters $aScalarArgs = array_merge($aScalarArgs, $value->ToArgsForQuery($sArgName)); } else { // Leave as is $aScalarArgs[$sArgName] = $value; } } else { if (!is_array($value)) { $aScalarArgs[$sArgName] = (string) $value; } } } $aScalarArgs['current_contact_id'] = UserRights::GetContactId(); return $aScalarArgs; }
/** * Give a default value for item_org_id (if relevant...) * @return void */ public function SetDefaultOrgId() { // First check that the organization CAN be fetched from the target class // $sClass = $this->Get('item_class'); $aCallSpec = array($sClass, 'MapContextParam'); if (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter if (MetaModel::IsValidAttCode($sClass, $sAttCode)) { // Second: check that the organization CAN be fetched from the current user // if (MetaModel::IsValidClass('Person')) { $aCallSpec = array($sClass, 'MapContextParam'); if (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter if (MetaModel::IsValidAttCode($sClass, $sAttCode)) { // OK - try it // $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false); if ($oCurrentPerson) { $this->Set('item_org_id', $oCurrentPerson->Get($sAttCode)); } } } } } } }
public static function PrepareQueryArguments($aArgs) { // Translate any object into scalars // $aScalarArgs = array(); foreach ($aArgs as $sArgName => $value) { if (self::IsValidObject($value)) { if (strpos($sArgName, '->object()') === false) { // Lazy syntax - develop the object contextual parameters $aScalarArgs = array_merge($aScalarArgs, $value->ToArgsForQuery($sArgName)); } else { // Leave as is $aScalarArgs[$sArgName] = $value; } } else { if (is_scalar($value)) { $aScalarArgs[$sArgName] = (string) $value; } elseif (is_null($value)) { $aScalarArgs[$sArgName] = null; } } } // Add standard contextual arguments // $aScalarArgs['current_contact_id'] = UserRights::GetContactId(); return $aScalarArgs; }
/** * Lifecycle action: Set the current logged in CONTACT for the given attribute */ public function SetCurrentPerson($sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); if ($oAttDef instanceof AttributeString) { $iPerson = UserRights::GetContactId(); if ($iPerson == 0) { $this->Set($sAttCode, ''); } else { $oPerson = MetaModel::GetObject('Person', $iPerson); $this->Set($sAttCode, $oPerson->Get('friendlyname')); } } else { if ($oAttDef->IsExternalKey()) { if (!MetaModel::IsParentClass($oAttDef->GetTargetClass(), 'Person')) { throw new Exception("SetCurrentContact: the attribute {$sAttCode} must be an external key to 'Person' or any other class above 'Person', found '" . $oAttDef->GetTargetClass() . "'"); } } $this->Set($sAttCode, UserRights::GetContactId()); } return true; }