public function action_index()
 {
     $steps = self::$steps;
     // error verification
     if (empty($steps)) {
         throw new Exception('No steps?');
     }
     // building form first
     $input = request::input();
     $ms = '<div class="form">';
     $ms .= '<table width="100%" class="simple">';
     if (sizeof($steps) > 1) {
         $ms .= '<tr><td width="1%">' . h::radio(array('name' => 'execute_step', 'class' => 'radio', 'value' => 'all', 'checked' => @$input['execute_step'] == 'all' ? true : false)) . '</td><td>All steps</td></tr>';
     }
     foreach ($steps as $k => $v) {
         $ms .= '<tr><td width="1%">' . h::radio(array('name' => 'execute_step', 'class' => 'radio', 'value' => $k, 'checked' => @$input['execute_step'] == $k ? true : false)) . '</td><td>Step ' . $k . ' ' . $v['name'] . '</td></tr>';
         // appending extra html
         if (!empty($v['html'])) {
             $ms .= '<tr><td width="1%"></td><td>' . $v['html'] . '</td></tr>';
         }
     }
     $ms .= '</table>';
     $ms .= '<br />';
     $ms .= h::submit(array('name' => 'submit', 'class' => 'button yellow'));
     $ms .= '</div>';
     $ms = h::form(array('name' => 'executioner', 'value' => $ms));
     echo h::frame($ms, 'simple');
     // executing steps
     if (!empty($input['execute_step'])) {
         $time_start = time();
         //echo '<hr />';
         foreach ($steps as $k => $v) {
             // double check
             if (!isset($v['execute'])) {
                 throw new Exception('execute?');
             }
             // executing
             if ($input['execute_step'] == 'all' || $input['execute_step'] == $k) {
                 echo '<hr /><h4>Step [' . $k . '. ' . $v['name'] . ']: </h4>';
                 // redirecting request if set
                 $params = array();
                 if (!empty($input['redirect_request'][$k])) {
                     $params = $input['redirect_request'][$k];
                 } else {
                     if (!empty($v['params'])) {
                         $params = $v['params'];
                     }
                 }
                 // we will be keeping alive
                 alive::start();
                 $result2 = call_user_func_array($v['execute'], $params);
                 alive::stop();
                 // processing result
                 if (is_scalar($result2)) {
                     echo $result2;
                 } else {
                     if (is_array($result2)) {
                         if (@$result2['hint']) {
                             layout::add_message($result2['hint'], 'info');
                         }
                         if (@$result2['error']) {
                             layout::add_message($result2['error'], 'error');
                             // important: we terminate batch
                             echo 'Batch terminated due to error!';
                             break;
                         }
                     }
                 }
             }
         }
         // time
         $time_end = time();
         echo '<hr />';
         echo '<b>Run time: ' . ($time_end - $time_start) . 'sec</b>';
     }
 }
Example #2
0
 /**
  *
  */
 public function toHtml(array $params = array(), array $innerCallbacks = array())
 {
     require_once 'lib/lib.htmlgen.php';
     $o = $this;
     //h::li(function () use ($o, $params, $innerCallbacks) {
     h::li(array('id' => $o->getInternalId()), function () use($o, $params, $innerCallbacks) {
         h::div(array('class' => 'builderElementLine'), function () use($o, $params) {
             h::h3($params['title']);
             /*
                       h::div(array('class' => 'builderElementActionItems'), function() use ($o) {
                         if ($o->isEditable()) {
                           h::a('Details', '#', array('class' => 'btn details'));
                         }
                         if ($o->isDeletable()) {
                           h::a('Delete', '#', array('class' => 'delete btn danger'));
                         }
                       });*/
         });
         h::div(array('class' => 'popover builderElementPopover right'), function () use($o, $params, $innerCallbacks) {
             h::div(array('class' => 'arrow'));
             h::div(array('class' => 'inner'), function () use($o, $params, $innerCallbacks) {
                 h::h3(array('class' => 'title'), function () use($o, $params) {
                     h::div(array('class' => 'actualTitle'), 'Details for ' . $params['title']);
                 });
                 h::div(array('class' => 'content'), function () use($o, $innerCallbacks) {
                     h::form(array('class' => 'form', 'action' => ''), function () use($o, $innerCallbacks) {
                         h::fieldset(function () use($o, $innerCallbacks) {
                             $params = array('help' => "Uncheck this if you don't want this task to execute at all.", 'label' => 'Active?', 'name' => 'active', 'checked' => $o->isActive());
                             $o->getHtmlInputCheckbox($params);
                             foreach ($innerCallbacks as $cb) {
                                 //
                                 // Filesets are special cases, because we might need to
                                 // iterate on more than one (in the future)
                                 //
                                 if ($cb['cb'] == 'getFilesets') {
                                     if ($o->getFilesets()) {
                                         $filesets = $o->getFilesets();
                                         foreach ($filesets as $fileset) {
                                             $fileset->toHtml();
                                         }
                                     }
                                     //
                                     // Normal to-HTML callbacks
                                     //
                                 } else {
                                     call_user_func(array($o, $cb['cb']), $cb);
                                 }
                             }
                             h::div(array('class' => 'actions'), function () {
                                 h::input(array('type' => 'submit', 'class' => 'btn', 'value' => 'Nothing to save', 'disabled' => 'disabled'));
                                 h::button(array('class' => 'btn delete danger'), 'Delete');
                             });
                         });
                     });
                 });
             });
         });
     });
     //});
 }
Example #3
0
 /**
  * Module page generation, menus rendering, blocks processing, adding of form with save/apply/cancel/reset and/or custom users buttons
  */
 protected function generate()
 {
     $Config = Config::instance();
     $L = Language::instance();
     $Page = Page::instance();
     if ($this->api) {
         $Page->content($this->Content);
         return;
     }
     $this->main_menu_auto && $this->main_menu();
     $this->main_sub_menu_auto && $this->main_sub_menu();
     $this->main_menu_more_auto && $this->main_menu_more();
     $this->blocks_processing();
     if ($this->form) {
         $Page->content(h::form($this->Content . ($this->apply_button && $this->buttons ? h::button($L->apply, ['name' => 'edit_settings', 'data-title' => $L->apply_info, 'id' => 'apply_settings', 'type' => 'submit', 'value' => 'apply', 'add' => Cache::instance()->cache_state() ? '' : ' disabled']) : '') . ($this->save_button && $this->buttons ? h::button($L->save, ['name' => 'edit_settings', 'data-title' => $L->save_info, 'id' => 'save_settings', 'type' => 'submit', 'value' => 'save']) : '') . ($this->apply_button && $this->buttons || $this->cancel_button_back ? h::button($L->cancel, ['name' => 'edit_settings', 'id' => 'cancel_settings', 'value' => 'cancel', 'data-title' => $this->cancel_button_back ? false : $L->cancel_info, 'type' => $this->cancel_button_back ? 'button' : 'submit', 'onClick' => $this->cancel_button_back ? 'history.go(-1);' : false, 'add' => $this->cancel_button_back ? '' : (isset($Config->core['cache_not_saved']) ? '' : $this->cancel_button)]) : '') . ($this->buttons && $this->reset_button ? h::button($L->reset, ['id' => 'reset_settings', 'data-title' => $L->reset_info, 'type' => 'reset']) : '') . $this->post_buttons, array_merge(['enctype' => $this->file_upload ? 'multipart/form-data' : false, 'action' => $this->action], $this->form_atributes)));
     } elseif ($this->Content) {
         $Page->content($this->Content);
     }
 }