예제 #1
0
 /**
  * Make sure PHP is up to snuff, that we can write to the right places, and
  * make the first user.
  */
 public function indexAction()
 {
     $phpCheck = array('PHP Version >= 5.2.3' => version_compare(PHP_VERSION, '5.2.3') >= 0, 'Standard Extension Loaded' => extension_loaded('standard'), 'SOAP Extension Loaded' => extension_loaded('soap'), 'PCRE Extension Loaded' => extension_loaded('pcre'), 'PDO Extension Loaded' => extension_loaded('pdo'), 'PDO SQLite Extension Loaded' => extension_loaded('pdo_sqlite'), 'SPL Extension Loaded' => extension_loaded('spl'), 'Session Extension Loaded' => extension_loaded('session'), 'Ctype Extension Loaded' => extension_loaded('ctype'));
     $systemCheck = array('Languages Directory (' . LANGUAGE_PATH . ') Writable' => is_writable(LANGUAGE_PATH), 'Skins Directory (' . SKIN_PATH . ') Writable' => is_writable(SKIN_PATH), 'Database Directory (' . APPLICATION_PATH . '/../data/db) Writable' => is_writable(APPLICATION_PATH . '/../data/db'), 'Configuration File (' . CONFIG_PATH . '/settings.ini' . ') Writable' => is_writable(CONFIG_PATH . '/settings.ini'));
     /*
      * Show an error if there are any PHP or system errors.
      */
     $hasPhpErrors = false;
     $hasSystemErrors = false;
     foreach ($phpCheck as $check) {
         if (!$check) {
             $hasPhpErrors = true;
             break;
         }
     }
     foreach ($systemCheck as $check) {
         if (!$check) {
             $hasSystemErrors = true;
             break;
         }
     }
     if (!$hasPhpErrors && !$hasSystemErrors) {
         /*
          * Build the add user form.
          */
         $config = Zend_Registry::get('config');
         $skins = Model_Skin::getAllSkins();
         $languages = Model_Language::getAllLanguages();
         /*
          * Turn the skin and language lists into something more Zend_Form
          * friendly.
          */
         foreach ($skins as $skin) {
             $skinList[$skin->name] = $skin->name;
         }
         foreach ($languages as $language) {
             $languageList[$language->name] = $language->name;
         }
         $form = new Zend_Form();
         $form->setMethod('post');
         $username = $form->createElement('text', 'username');
         $username->setLabel(ucfirst($this->view->translate->_('username')));
         $username->setRequired(true);
         $username->addValidator('alnum');
         $apiKey = $form->createElement('text', 'apiKey');
         $apiKey->setLabel(ucfirst($this->view->translate->_('API key')));
         $apiKey->setRequired(true);
         $apiKey->addValidator('alnum');
         $skin = $form->createElement('select', 'skin');
         $skin->setLabel(ucfirst($this->view->translate->_('skin')));
         $skin->addMultiOptions($skinList);
         $skin->setValue($config->defaults->skin);
         $skin->setRequired(true);
         $language = $form->createElement('select', 'language');
         $language->setLabel(ucfirst($this->view->translate->_('language')));
         $language->addMultiOptions($languageList);
         $language->setValue($config->defaults->language);
         $language->setRequired(true);
         $form->addElement($username);
         $form->addElement($apiKey);
         $form->addElement($skin);
         $form->addElement($language);
         $form->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         /*
          * Process form submission.
          */
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             if ($form->isValid($formData)) {
                 /*
                  * Try out the username and API key to make sure they
                  * entered a good one.
                  */
                 $account = null;
                 $client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $form->getValue('username'), $form->getValue('apiKey'));
                 try {
                     $account = $client->getObject();
                 } catch (Exception $e) {
                     $this->view->errorMessage = $this->view->translate->_('Please enter a valid username and API key combination.');
                 }
                 /*
                  * Add the user.
                  */
                 if ($account != null) {
                     try {
                         $user = Model_DbTable_User::addUser($form->getValue('username'), $form->getValue('apiKey'), $form->getValue('skin'), $form->getValue('language'), true);
                         $this->_helper->_redirector->goToRouteAndExit(array('controller' => 'index', 'action' => null));
                     } catch (Exception $e) {
                         $this->view->errorMessage = $this->view->translate->_('Unable to add user.') . ' ' . $e->getMessage();
                     }
                 }
             } else {
                 $this->view->errorMessage = $this->view->translate->_('Please completely fill out the configuration form.');
             }
             $form->populate($formData);
         }
         $this->view->form = $form;
     }
     $this->view->pageTitle = 'Installation';
     $this->view->headTitle('Installation');
     $this->view->phpCheck = $phpCheck;
     $this->view->systemCheck = $systemCheck;
     $this->view->hasPhpErrors = $hasPhpErrors;
     $this->view->hasSystemErrors = $hasSystemErrors;
 }
예제 #2
0
 public function editskinAction()
 {
     $skin = null;
     $config = Zend_Registry::get('config');
     /*
      * Retrieve the skin.
      */
     try {
         $skin = new Model_Skin($this->_getParam('name'));
     } catch (Exception $e) {
         $this->view->errorMessage = $this->translate->_('Unable to locate skin.') . ' ' . $e->getMessage();
     }
     if ($skin != null) {
         /*
          * Build the delete form. Only show it if the skin is not the default system skin.
          */
         $deleteForm = null;
         if ($skin->name != $config->defaults->skin) {
             $deleteForm = new Zend_Form();
             $deleteForm->setMethod('post');
             $hidden = $deleteForm->createElement('hidden', 'mode');
             $hidden->setValue('delete');
             $deleteForm->addElement($hidden);
             $deleteForm->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         }
         /*
          * Build the edit forms. One for the logo, one for the css.
          */
         $skins = Model_Skin::getAllSkins();
         $logoForm = new Zend_Form();
         $logoForm->setMethod('post');
         $logoForm->setAttrib('enctype', 'multipart/form-data');
         $logo = $logoForm->createElement('file', 'logo');
         $logo->setLabel(ucfirst($this->view->translate->_('new logo')));
         $logo->addValidator('Count', false, 1);
         $logo->setRequired(true);
         $logo->addValidator('Extension', false, 'png');
         $logo->setDestination($skin->path . '/images');
         $hidden = $logoForm->createElement('hidden', 'mode');
         $hidden->setValue('logo');
         $logoForm->addElement($logo);
         $logoForm->addElement($hidden);
         $logoForm->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         $cssForm = new Zend_Form();
         $cssForm->setMethod('post');
         $css = $cssForm->createElement('textarea', 'css');
         $css->setRequired(true);
         $css->setValue($skin->getCssContent());
         $css->setAttrib('rows', '24');
         $css->setAttrib('cols', '80');
         $css->setAttrib('style', 'margin-left: 60px;');
         $hidden = $cssForm->createElement('hidden', 'mode');
         $hidden->setValue('css');
         $cssForm->addElement($css);
         $cssForm->addElement($hidden);
         $cssForm->addElement('submit', 'submit', array('label' => $this->view->translate->_('Submit')));
         /*
          * Process form submission.
          */
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             switch ($formData['mode']) {
                 /*
                  * Delete the skin.
                  */
                 case 'delete':
                     /*
                      * You may not delete the default system skin.
                      */
                     if ($skin->name == $config->defaults->skin) {
                         $this->view->errorMessage = $this->view->translate->_('You may not delete the default system skin.');
                     } else {
                         try {
                             $skin->deleteSkin();
                             $this->_helper->_redirector->goToRouteAndExit(array('controller' => 'admin', 'action' => 'skins', 'id' => null, 'name' => null));
                         } catch (Exception $e) {
                             $this->view->errorMessage = $this->view->translate->_('Unable to delete skin.') . ' ' . $e->getMessage();
                         }
                     }
                     break;
                     /*
                      * Change the logo.
                      */
                 /*
                  * Change the logo.
                  */
                 case 'logo':
                     if ($logoForm->isValid($formData)) {
                         if ($logoForm->logo->receive()) {
                             rename($logoForm->logo->getFileName(), $skin->path . '/images/logo.png');
                             $this->view->statusMessage = $this->view->translate->_('Skin saved.');
                         } else {
                             $this->view->errorMessage = $this->view->translate->_('Unable to save skin.') . ' ' . $e->getMessage();
                         }
                     } else {
                         $this->view->errorMessage = $this->view->translate->_('Please completely fill out the configuration form.');
                     }
                     break;
                     /*
                      * Change the CSS
                      */
                 /*
                  * Change the CSS
                  */
                 case 'css':
                     if ($cssForm->isValid($formData)) {
                         try {
                             $skin->updateCss($cssForm->getValue('css'));
                             $this->view->statusMessage = $this->view->translate->_('Skin saved.');
                         } catch (Exception $e) {
                             $this->view->errorMessage = $this->view->translate->_('Unable to save skin.') . ' ' . $e->getMessage();
                         }
                     } else {
                         $this->view->errorMessage = $this->view->translate->_('Please completely fill out the configuration form.');
                     }
                     $cssForm->populate($formData);
                     break;
             }
         }
         $this->view->pageTitle = $this->view->translate->_('Edit') . ' ' . $skin->name;
         $this->view->headTitle($this->view->translate->_('Edit') . ' ' . $skin->name);
         $this->view->logoForm = $logoForm;
         $this->view->cssForm = $cssForm;
         $this->view->deleteForm = $deleteForm;
     }
     $this->view->skin = $skin;
 }