示例#1
0
 /**
  * Apply a license
  *
  * @return     void
  */
 public function savelicenseTask()
 {
     $id = Request::getInt('toolid', 0, 'post');
     $error = '';
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller));
     }
     $hztv = \Components\Tools\Helpers\Version::getDevelopmentToolVersion($id);
     $this->license_choice = array('text' => Request::getVar('license', ''), 'template' => Request::getVar('templates', 'c1'), 'authorize' => Request::getInt('authorize', 0));
     $hztv->codeaccess = Request::getVar('t_code', '@OPEN');
     $action = Request::getWord('action', 'dev');
     // Closed source
     if ($hztv->codeaccess == '@DEV') {
         $reason = Request::getVar('reason', '');
         if (!$reason) {
             $this->view->license_choice = $this->license_choice;
             $this->view->code = $hztv->codeaccess;
             // display license page with error
             $this->setError(Lang::txt('COM_TOOLS_LICENSE_CLOSED_SOURCE_NEED_REASON'));
             $this->licenseTask();
             return;
         } else {
             $path = DS . 'site/protected';
             if (is_dir(PATH_APP . $path)) {
                 $log = 'By: ' . User::get('name') . ' (' . User::get('username') . ') ' . "\n";
                 $log .= 'Tool: ' . $hztv->toolname . ' (id #' . $id . ')' . ' - ' . $hztv->instance . "\n";
                 $log .= 'Time : ' . date('c') . "\n";
                 $log .= 'Reason for closed source: ' . "\n";
                 $log .= $reason . "\n";
                 $log .= '-----------------------------------------' . "\n";
                 // Log reason for closed source
                 $this->_writeToFile($log, PATH_APP . $path . DS . 'closed_source_reasons.txt', true);
             }
             // code for saving license
             $hztv->license = NULL;
             // save version info
             $hztv->update();
             //@FIXME: look
             $this->_setTracAccess($hztv->toolname, $hztv->codeaccess, null);
             if ($action != 'confirm') {
                 $this->_msg = Lang::txt('COM_TOOLS_NOTICE_CHANGE_LICENSE_SAVED');
                 $this->statusTask();
             } else {
                 $this->finalizeTask();
             }
             return;
         }
     }
     // Open source
     if (\Components\Tools\Models\Tool::validateLicense($this->license_choice, $hztv->codeaccess, $error)) {
         // code for saving license
         $hztv->license = strip_tags($this->license_choice['text']);
         // save version info
         $hztv->update();
         //@FIXME: look
         $this->_setTracAccess($hztv->toolname, $hztv->codeaccess, null);
         if ($action != 'confirm') {
             $this->_msg = Lang::txt('COM_TOOLS_NOTICE_CHANGE_LICENSE_SAVED');
             $this->statusTask();
         } else {
             $this->finalizeTask();
         }
     } else {
         $this->view->code = $hztv->codeaccess;
         $this->view->license_choice = $this->license_choice;
         // display license page with error
         $this->setError($error);
         $this->licenseTask();
     }
 }