Ejemplo n.º 1
0
/**
 * Displays a popup welcome message, once per session at maximum
 * until the user unchecks the "Display welcome at startup"
 * @param WebPage $oP The current web page for the display
 * @return void
 */
function DisplayWelcomePopup(WebPage $oP)
{
    if (!isset($_SESSION['welcome'])) {
        // Check, only once per session, if the popup should be displayed...
        // If the user did not already ask for hiding it forever
        $bPopup = appUserPreferences::GetPref('welcome_popup', true);
        if ($bPopup) {
            $sTemplate = @file_get_contents('../application/templates/welcome_popup.html');
            if ($sTemplate !== false) {
                $oTemplate = new DisplayTemplate($sTemplate);
                $oP->add("<div id=\"welcome_popup\">");
                $oTemplate->Render($oP, array());
                $oP->add("<p style=\"float:left\"><input type=\"checkbox\" checked id=\"display_welcome_popup\"/><label for=\"display_welcome_popup\">&nbsp;" . Dict::S('UI:DisplayThisMessageAtStartup') . "</label></p>\n");
                $oP->add("<p style=\"float:right\"><input type=\"button\" value=\"" . Dict::S('UI:Button:Ok') . "\" onClick=\"\$('#welcome_popup').dialog('close');\"/>\n");
                $oP->add("</div>\n");
                $sTitle = addslashes(Dict::S('UI:WelcomeMenu:Title'));
                $oP->add_ready_script(<<<EOF
\t\$('#welcome_popup').dialog( { width:'80%', height: 'auto', title: '{$sTitle}', autoOpen: true, modal:true,
\t\t\t\t\t\t\t\t  close: function() {
\t\t\t\t\t\t\t\t  \tvar bDisplay = \$('#display_welcome_popup:checked').length;
\t\t\t\t\t\t\t\t  \tSetUserPreference('welcome_popup', bDisplay, true); 
\t\t\t\t\t\t\t\t  }
\t\t\t\t\t\t\t\t  });
\tif (\$('#welcome_popup').height() > (\$(window).height()-70))
\t{
\t\t\$('#welcome_popup').height(\$(window).height()-70);
\t}
EOF
);
                $_SESSION['welcome'] = 'ok';
            }
        }
    }
}
 function DisplayDetails(WebPage $oPage, $bEditMode = false)
 {
     $sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
     if (!empty($sTemplate)) {
         $oTemplate = new DisplayTemplate($sTemplate);
         // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved
         //       but the preferred method is to use '$id$'
         $oTemplate->Render($oPage, array('class_name' => MetaModel::GetName(get_class($this)), 'class' => get_class($this), 'pkey' => $this->GetKey(), 'id' => $this->GetKey(), 'name' => $this->GetName()));
     } else {
         // Object's details
         // template not found display the object using the *old style*
         $this->DisplayBareHeader($oPage, $bEditMode);
         $oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
         $oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
         $oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
         $this->DisplayBareProperties($oPage, $bEditMode);
         $this->DisplayBareRelations($oPage, $bEditMode);
         //$oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
         //$this->DisplayBareHistory($oPage, $bEditMode);
         $oPage->AddAjaxTab(Dict::S('UI:HistoryTab'), utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.render.php?operation=history&class=' . get_class($this) . '&id=' . $this->GetKey());
     }
 }
Ejemplo n.º 3
0
 public function Render(WebPage $oPage, $aParams = array(), $bEditMode = false)
 {
     $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this->m_oObj));
     $aTemplateFields = array();
     preg_match_all('/\\$this->([a-z0-9_]+)\\$/', $this->m_sTemplate, $aMatches);
     foreach ($aMatches[1] as $sAttCode) {
         if (MetaModel::IsValidAttCode(get_class($this->m_oObj), $sAttCode)) {
             $aTemplateFields[] = $sAttCode;
         } else {
             $aParams['this->' . $sAttCode] = "<!--Unknown attribute: {$sAttCode}-->";
         }
     }
     preg_match_all('/\\$this->field\\(([a-z0-9_]+)\\)\\$/', $this->m_sTemplate, $aMatches);
     foreach ($aMatches[1] as $sAttCode) {
         if (MetaModel::IsValidAttCode(get_class($this->m_oObj), $sAttCode)) {
             $aTemplateFields[] = $sAttCode;
         } else {
             $aParams['this->field(' . $sAttCode . ')'] = "<!--Unknown attribute: {$sAttCode}-->";
         }
     }
     $aFieldsComments = isset($aParams['fieldsComments']) ? $aParams['fieldsComments'] : array();
     $aFieldsMap = array();
     $sClass = get_class($this->m_oObj);
     // Renders the fields used in the template
     foreach (MetaModel::ListAttributeDefs(get_class($this->m_oObj)) as $sAttCode => $oAttDef) {
         $aParams['this->label(' . $sAttCode . ')'] = $oAttDef->GetLabel();
         $aParams['this->comments(' . $sAttCode . ')'] = isset($aFieldsComments[$sAttCode]) ? $aFieldsComments[$sAttCode] : '';
         $iInputId = '2_' . $sAttCode;
         // TODO: generate a real/unique prefix...
         if (in_array($sAttCode, $aTemplateFields)) {
             if ($this->m_oObj->IsNew()) {
                 $iFlags = $this->m_oObj->GetInitialStateAttributeFlags($sAttCode);
             } else {
                 $iFlags = $this->m_oObj->GetAttributeFlags($sAttCode);
             }
             if ($iFlags & OPT_ATT_MANDATORY && $this->m_oObj->IsNew()) {
                 $iFlags = $iFlags & ~OPT_ATT_READONLY;
                 // Mandatory fields cannot be read-only when creating an object
             }
             if (!$oAttDef->IsWritable() || $sStateAttCode == $sAttCode) {
                 $iFlags = $iFlags | OPT_ATT_READONLY;
             }
             if ($iFlags & OPT_ATT_HIDDEN) {
                 $aParams['this->label(' . $sAttCode . ')'] = '';
                 $aParams['this->field(' . $sAttCode . ')'] = '';
                 $aParams['this->comments(' . $sAttCode . ')'] = '';
                 $aParams['this->' . $sAttCode] = '';
             } else {
                 if ($bEditMode && $iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE)) {
                     // Check if the attribute is not read-only because of a synchro...
                     $aReasons = array();
                     $sSynchroIcon = '';
                     if ($iFlags & OPT_ATT_SLAVE) {
                         $iSynchroFlags = $this->m_oObj->GetSynchroReplicaFlags($sAttCode, $aReasons);
                         $sSynchroIcon = "&nbsp;<img id=\"synchro_{$sInputId}\" src=\"../images/transp-lock.png\" style=\"vertical-align:middle\"/>";
                         $sTip = '';
                         foreach ($aReasons as $aRow) {
                             $sTip .= "<p>Synchronized with {$aRow['name']} - {$aRow['description']}</p>";
                         }
                         $oPage->add_ready_script("\$('#synchro_{$iInputId}').qtip( { content: '{$sTip}', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );");
                     }
                     // Attribute is read-only
                     $sHTMLValue = "<span id=\"field_{$iInputId}\">" . $this->m_oObj->GetAsHTML($sAttCode);
                     $sHTMLValue .= '<input type="hidden" id="' . $iInputId . '" name="attr_' . $sAttCode . '" value="' . htmlentities($this->m_oObj->Get($sAttCode), ENT_QUOTES, 'UTF-8') . '"/></span>';
                     $aFieldsMap[$sAttCode] = $iInputId;
                     $aParams['this->comments(' . $sAttCode . ')'] = $sSynchroIcon;
                 }
                 if ($bEditMode && !($iFlags & OPT_ATT_READONLY)) {
                     $aParams['this->field(' . $sAttCode . ')'] = "<span id=\"field_{$iInputId}\">" . $this->m_oObj->GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $this->m_oObj->Get($sAttCode), $this->m_oObj->GetEditValue($sAttCode), $iInputId, '', $iFlags, array('this' => $this->m_oObj)) . '</span>';
                     $aFieldsMap[$sAttCode] = $iInputId;
                 } else {
                     $aParams['this->field(' . $sAttCode . ')'] = $this->m_oObj->GetAsHTML($sAttCode);
                 }
                 $aParams['this->' . $sAttCode] = "<table class=\"field\"><tr><td class=\"label\">" . $aParams['this->label(' . $sAttCode . ')'] . ":</td><td>" . $aParams['this->field(' . $sAttCode . ')'] . "</td><td>" . $aParams['this->comments(' . $sAttCode . ')'] . "</td></tr></table>";
             }
         }
     }
     // Renders the PlugIns used in the template
     preg_match_all('/\\$PlugIn:([A-Za-z0-9_]+)->properties\\(\\)\\$/', $this->m_sTemplate, $aMatches);
     $aPlugInProperties = $aMatches[1];
     foreach ($aPlugInProperties as $sPlugInClass) {
         $oInstance = MetaModel::GetPlugins('iApplicationUIExtension', $sPlugInClass);
         if ($oInstance != null) {
             $offset = $oPage->start_capture();
             $oInstance->OnDisplayProperties($this->m_oObj, $oPage, $bEditMode);
             $sContent = $oPage->end_capture($offset);
             $aParams["PlugIn:{$sPlugInClass}->properties()"] = $sContent;
         } else {
             $aParams["PlugIn:{$sPlugInClass}->properties()"] = "Missing PlugIn: {$sPlugInClass}";
         }
     }
     $offset = $oPage->start_capture();
     parent::Render($oPage, $aParams);
     $sContent = $oPage->end_capture($offset);
     // Remove empty table rows in case some attributes are hidden...
     $sContent = preg_replace('/<tr[^>]*>\\s*(<td[^>]*>\\s*<\\/td>)+\\s*<\\/tr>/im', '', $sContent);
     $oPage->add($sContent);
     return $aFieldsMap;
 }
Ejemplo n.º 4
0
 public function RenderContent(WebPage $oPage, $aExtraParams = array())
 {
     $sTemplate = @file_get_contents($this->sTemplateFile);
     if ($sTemplate !== false) {
         $aExtraParams['table_id'] = 'Menu_' . $this->GetMenuId();
         $oTemplate = new DisplayTemplate($sTemplate);
         $oTemplate->Render($oPage, $aExtraParams);
     } else {
         $oPage->p("Error: failed to load template file: '{$this->sTemplateFile}'");
         // No need to translate ?
     }
 }