/**
  * Recreate the tabs in the dialog
  */
 protected function SetupTabs()
 {
     $strClassNames = $this->CreateClassNameArray();
     $this->tabs->RemoveChildControls(true);
     $this->categories = array();
     $this->dtgGeneralOptions = new QHtmlTable($this->tabs, 'definitionTab');
     $this->dtgGeneralOptions->ShowHeader = false;
     $this->dtgGeneralOptions->Name = "General";
     $this->dtgGeneralOptions->CreatePropertyColumn('Attribute', 'Name');
     $col = $this->dtgGeneralOptions->AddColumn(new QHtmlTableCallableColumn('Attribute', array($this, 'dtg_ValueRender'), $this->dtgGeneralOptions));
     $col->HtmlEntities = false;
     $this->dtgGeneralOptions->SetDataBinder('dtgGeneralOptions_Bind', $this);
     /**
      * The following default options are somewhat matched to the default list and edit templates. A more robust
      * implementation would get the options from the templates, or what the templates generate, so that the templates
      * decide what to put there. If someone wants to radically change the templates, but still have them use this dialog
      * to edit the options, then would be the time to change the code below.
      */
     if ($this->objCurrentControl->LinkedNode->_ParentNode) {
         // Specify general options for a database column
         $this->generalOptions = array(new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ControlClass', 'Override of the PHP type for the control. If you change this, save the dialog and reopen to reload the tabs to show the control specific options.', QModelConnectorParam::SelectionList, $strClassNames), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'FormGen', 'Whether or not to generate this object, just a label for the object, just the control, or both the control and label', QModelConnectorParam::SelectionList, array(QFormGen::Both => 'Both', QFormGen::None => 'None', QFormGen::ControlOnly => 'Control', QFormGen::LabelOnly => 'Label')), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'Name', 'Control\'s Name', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'NoColumn', 'True to prevent a column in the lister from being generated.', QType::Boolean));
     } else {
         // Specify general options for a database table, meaning an object that is listing the content of a whole table.
         // These would be options at a higher level than the control itself, and would modify how the control is used in a form.
         $this->generalOptions = array(new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ControlClass', 'Override of the PHP type for the control. If you change this, save the dialog and reopen to reload the tabs to show the control specific options.', QModelConnectorParam::SelectionList, $strClassNames), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'Name', 'The Control\'s Name. Generally leave this blank, or use a plural name.', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'ItemName', 'The public name of an item in the list. Its used by the title of the edit form, for example. Defaults to the name of the table in the database.', QType::String), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'CreateFilter', 'Whether to generate a separate control to filter the data. If the data list control does its own filtering, set this to false. Default is true.', QType::Boolean), new QModelConnectorParam(QModelConnectorParam::GeneralCategory, 'EditMode', 'How to edit an item. 1) Options are: to go to a separate form, 2) popup a dialog, or 3) popup a dialog only if not on a mobile device since mobile devices struggle with showing dialogs that are bigger than the screen.', QModelConnectorParam::SelectionList, array('form' => 'Edit with a QForm', 'dialog' => 'Edit with a QDialog', 'both' => 'Edit with a form on mobile devices, and a dialog on desktops.')));
     }
     // load values from settings file
     foreach ($this->generalOptions as $objParam) {
         $objControl = $objParam->GetControl($this->dtgGeneralOptions);
         // get a control that will edit this option
         $strName = $objControl->Name;
         if (isset($this->params[$strName])) {
             $objControl->Value = $this->params[$strName];
             if ($strName == 'ControlClass') {
                 $strControlClass = $this->params[$strName];
             }
         } else {
             $objControl->Value = null;
         }
     }
     if (!isset($strControlClass)) {
         $strControlClass = get_class($this->objCurrentControl);
     }
     $params = $strControlClass::GetModelConnectorParams();
     // gather categories
     foreach ($params as $param) {
         $this->categories[$param->Category][] = $param;
     }
     // Add any additional general items to the general tab
     if (isset($this->categories[QModelConnectorParam::GeneralCategory])) {
         // load values from settings file
         foreach ($this->categories[QModelConnectorParam::GeneralCategory] as $objParam) {
             $objControl = $objParam->GetControl($this->dtgGeneralOptions);
             // get a control that will edit this option
             $strName = $objControl->Name;
             if (isset($this->params[$strName])) {
                 $objControl->Value = $this->params[$strName];
             } else {
                 $objControl->Value = null;
             }
             $this->generalOptions[] = $objParam;
         }
         unset($this->categories[QModelConnectorParam::GeneralCategory]);
     }
     foreach ($this->categories as $tabName => $params) {
         $panel = new QPanel($this->tabs);
         $panel->SetCustomStyle('overflow-y', 'scroll');
         $panel->SetCustomStyle('max-height', '200');
         $panel->AutoRenderChildren = true;
         $panel->Name = $tabName;
         $dtg = new QHtmlTable($panel);
         $dtg->ShowHeader = false;
         $dtg->CreatePropertyColumn('Attribute', 'Name');
         $col = $dtg->AddColumn(new QHtmlTableCallableColumn('Attribute', array($this, 'dtg_ValueRender'), $dtg));
         $col->HtmlEntities = false;
         $dtg->SetDataBinder('dtgControlBind', $this);
         $dtg->Name = $tabName;
         // holder for category
         $this->datagrids[$tabName] = $dtg;
         // load values from settings file
         foreach ($params as $objParam) {
             $objControl = $objParam->GetControl($this->datagrids[$tabName]);
             if ($objControl) {
                 $strName = $objControl->Name;
                 if (isset($this->params['Overrides'][$strName])) {
                     $objControl->Value = $this->params['Overrides'][$strName];
                 } else {
                     $objControl->Value = null;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public function __construct($objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = __NARRO_INCLUDES__ . '/narro/panel/NarroUserLoginPanel.tpl.php';
     $this->lblMessage = new QLabel($this);
     $this->lblMessage->HtmlEntities = false;
     $this->objAccordion = new QAccordion($this);
     $lblNarroLogin = new QLinkButton($this->objAccordion);
     $lblNarroLogin->Text = t('Login with your Narro account');
     $pnlNarroLogin = new QPanel($this->objAccordion);
     $pnlNarroLogin->AutoRenderChildren = true;
     $pnlNarroLogin->PreferedRenderMethod = 'RenderWithName';
     $pnlNarroLogin->SetCustomStyle('text-align', 'right');
     $this->txtUsername = new QTextBox($pnlNarroLogin, 'username');
     $this->txtUsername->TabIndex = 1;
     $this->txtUsername->Name = t('Username');
     $this->txtUsername->PreferedRenderMethod = 'RenderWithName';
     $this->txtPassword = new QTextBox($pnlNarroLogin, 'password');
     $this->txtPassword->TabIndex = 2;
     $this->txtPassword->TextMode = QTextMode::Password;
     $this->txtPassword->Name = t('Password');
     $this->txtPassword->PreferedRenderMethod = 'RenderWithName';
     $this->btnLogin = new QButton($pnlNarroLogin);
     $this->btnLogin->Text = t('Login');
     $this->btnLogin->PrimaryButton = true;
     $this->btnLogin->TabIndex = 3;
     $this->btnLogin->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnLogin_Click'));
     $lblOpenIdLogin = new QLinkButton($this->objAccordion);
     $lblOpenIdLogin->HtmlEntities = false;
     $lblOpenIdLogin->Text = '<img src="http://www.openid.net/favicon.ico" /> ' . t('Login with your OpenID');
     $pnlOpenIdLogin = new QPanel($this->objAccordion);
     $pnlOpenIdLogin->AutoRenderChildren = true;
     $this->txtOpenId = new QTextBox($pnlOpenIdLogin, 'openid');
     $this->txtOpenId->Name = t('OpenID URL');
     $this->txtOpenId->Instructions = t('Use your existing OpenID account information to login.');
     $this->txtOpenId->PreferedRenderMethod = 'RenderWithName';
     $this->btnOpenIdLogin = new QButton($pnlOpenIdLogin);
     $this->btnOpenIdLogin->Text = t('Login');
     $this->btnOpenIdLogin->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnOpenIdLogin_Click'));
     $lblGoogleLogin = new QLinkButton($this->objAccordion);
     $lblGoogleLogin->HtmlEntities = false;
     $lblGoogleLogin->Text = '<img src="http://www.google.com/favicon.ico" /> ' . t('Login with your Google account');
     $lblGoogleLogin->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnGoogleLogin_Click'));
     $pnlGoogleLogin = new QPanel($this->objAccordion);
     $pnlGoogleLogin->AutoRenderChildren = true;
     $lblBrowserIdLogin = new QLinkButton($this->objAccordion);
     $lblBrowserIdLogin->HtmlEntities = false;
     $lblBrowserIdLogin->Text = '<img src="https://browserid.org/favicon.ico" /> ' . t('Login with BrowserID');
     $lblBrowserIdLogin->AddAction(new QClickEvent(), new QJavaScriptAction(sprintf("navigator.id.get(function(assertion) {if (assertion) {qc.pA('%s', '%s', 'QClickEvent', assertion, '')} else {qc.pA('%s', '%s', 'QClickEvent', '', '')}}); return false;", $this->Form->FormId, $lblBrowserIdLogin->ControlId, $this->Form->FormId, $lblBrowserIdLogin->ControlId)));
     $lblBrowserIdLogin->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnBrowserIdLogin_Click'));
     $pnlBrowserIdLogin = new QPanel($this->objAccordion);
     $pnlBrowserIdLogin->AutoRenderChildren = true;
     $openid = new LightOpenID($_SERVER['HTTP_HOST']);
     if (!$openid->mode && isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '' && !strstr($_SERVER['HTTP_REFERER'], $_SERVER['REQUEST_URI'])) {
         $this->txtPreviousUrl = $_SERVER['HTTP_REFERER'];
     }
     if ($openid->mode) {
         if ($openid->mode == 'cancel') {
             $this->lblMessage->Text = t('The user has canceled authentication');
             $this->lblMessage->ForeColor = 'red';
         } else {
             if ($openid->validate()) {
                 $arrAttributes = $openid->getAttributes();
                 $objUser = NarroUser::LoadByUsername($openid->identity);
                 require_once __NARRO_INCLUDES__ . '/PasswordHash.class.php';
                 $objHasher = new PasswordHash(8, FALSE);
                 if (!$objUser instanceof NarroUser) {
                     try {
                         $objUser = NarroUser::RegisterUser($openid->identity, $openid->identity, '', $openid->identity);
                         if (isset($arrAttributes['namePerson'])) {
                             $objUser->Username = $arrAttributes['namePerson'];
                         }
                         if (isset($arrAttributes['contact/email'])) {
                             $objUser->Email = $arrAttributes['contact/email'];
                         }
                         $objUser->Save();
                     } catch (Exception $objEx) {
                         $this->lblMessage->ForeColor = 'red';
                         $this->lblMessage->Text = t('Failed to create an associated user for this OpenId') . $objEx->getMessage() . var_export($openid->identity, true);
                         return false;
                     }
                     $objUser->Reload();
                     QApplication::$Session->RegenerateId();
                     QApplication::$Session->User = $objUser;
                     QApplication::Redirect(NarroLink::UserPreferences($objUser->UserId));
                     exit;
                 } elseif ($objUser->Password != $objHasher->HashPassword('')) {
                     $this->lblMessage->ForeColor = 'red';
                     $this->lblMessage->Text = t('This user has a password set, please login with that instead');
                     return false;
                 }
                 QApplication::$Session->RegenerateId();
                 QApplication::$Session->User = $objUser;
                 QApplication::$User = $objUser;
                 if ($this->txtPreviousUrl) {
                     $strUrl = preg_replace('/([\\?\\&]l\\=)[a-z0-9\\-\\_]+/', '\\1' . QApplication::$User->GetPreferenceValueByName('Language'), $this->txtPreviousUrl);
                     if ($strUrl) {
                         QApplication::Redirect($strUrl);
                     } else {
                         QApplication::Redirect($this->txtPreviousUrl);
                     }
                 } else {
                     QApplication::Redirect(NarroLink::ProjectList(null, null, QApplication::$User->GetPreferenceValueByName('Language')));
                 }
                 exit;
             } else {
                 $this->lblMessage->Text = t('OpenID login failed');
                 $this->lblMessage->ForeColor = 'red';
             }
         }
     }
 }
Exemplo n.º 3
0
 protected function pnlFileDiff_Create($pnlWrap)
 {
     $pnlFileDiff = new QPanel($pnlWrap, $pnlWrap->ControlId . 'pnl');
     $pnlFileDiff->TagName = 'pre';
     $pnlFileDiff->Display = false;
     $pnlFileDiff->CssClass = 'section';
     $pnlFileDiff->HtmlEntities = false;
     $pnlFileDiff->SetCustomStyle('margin-left', '20px');
     return $pnlFileDiff;
 }