Beispiel #1
0
function applet_cron() {
    cmsCore::loadClass('cron');
    
    global $_LANG;
    
    global $adminAccess;
    
    if (!cmsUser::isAdminCan('admin/config', $adminAccess)) { cpAccessDenied(); }

    cmsCore::c('page')->setTitle($_LANG['AD_CRON_MISSION']);
    cpAddPathway($_LANG['AD_SITE_SETTING'], 'index.php?view=config');
    cpAddPathway($_LANG['AD_CRON_MISSION'], 'index.php?view=cron');

    $do = cmsCore::request('do', 'str', 'list');
    $id = cmsCore::request('id', 'int', '0');
    
    if ($do == 'list') {
        $toolmenu = array(
            array( 'icon' => 'new.gif', 'title' => $_LANG['AD_CREATE_CRON_MISSION'], 'link' => '?view=cron&do=add' )
        );

        cpToolMenu($toolmenu);

        $items = cmsCron::getJobs(false);

        $tpl_file   = 'admin/cron.php';
        $tpl_dir    = file_exists(TEMPLATE_DIR . $tpl_file) ? TEMPLATE_DIR : DEFAULT_TEMPLATE_DIR;

        include($tpl_dir . $tpl_file);
    }

    if ($do == 'show') {
        if ($id) { cmsCron::jobEnabled($id, true);  }
        cmsCore::halt('1');
    }
    
    if ($do == 'hide') {
        if ($id) { cmsCron::jobEnabled($id, false);  }
        cmsCore::halt('1');
    }
    
    if ($do == 'delete') {
        if ($id) { cmsCron::removeJobById($id); }
        cmsCore::redirect('index.php?view=cron');
    }
    
    if ($do == 'execute') {
        if ($id) { $job_result = cmsCron::executeJobById($id); }

        if ($job_result) {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_SUCCESS'], 'success');
        } else {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_ERROR'], 'error');
        }

        cmsCore::redirect('index.php?view=cron');
    }
    
    if ($do == 'submit') {
        if (!cmsUser::checkCsrfToken()) { cmsCore::error404(); }

        $job_name     = cmsCore::request('job_name', 'str');
        $comment      = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled      = cmsCore::request('enabled', 'int');
        $component    = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file  = cmsCore::request('custom_file', 'str');
        $custom_file  = (mb_stripos($custom_file, 'image') || mb_stripos($custom_file, 'upload') || mb_stripos($custom_file, 'cache')) ? '' : $custom_file;
        $custom_file  = preg_replace('/\.+\//', '', $custom_file);
        $class_name   = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');

        cmsCron::registerJob(
            $job_name,
            array(
                'interval' => $job_interval,
                'component' => $component,
                'model_method' => $model_method,
                'comment' => $comment,
                'custom_file' => $custom_file,
                'enabled' => $enabled,
                'class_name' => $class_name,
                'class_method' => $class_method
            )
        );

        cmsCore::redirect('index.php?view=cron');
    }
    
    if ($do == 'update') {
        if (!cmsUser::checkCsrfToken()) { cmsCore::error404(); }

        if (!$id) { cmsCore::halt(); }

        $job_name     = cmsCore::request('job_name', 'str');
        $comment      = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled      = cmsCore::request('enabled', 'int');
        $component    = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file  = cmsCore::request('custom_file', 'str');
        $custom_file  = (mb_stripos($custom_file, 'image') || mb_stripos($custom_file, 'upload') || mb_stripos($custom_file, 'cache')) ? '' : $custom_file;
        $custom_file  = preg_replace('/\.+\//', '', $custom_file);
        $class_name   = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');

        cmsCron::updateJob(
            $id,
            array(
                'job_name' => $job_name,
                'job_interval' => $job_interval,
                'component' => $component,
                'model_method' => $model_method,
                'comment' => $comment,
                'custom_file' => $custom_file,
                'is_enabled' => $enabled,
                'class_name' => $class_name,
                'class_method' => $class_method
            )
        );

        cmsCore::redirect('index.php?view=cron');
    }
    
    if ($do == 'edit' || $do == 'add') {
        $toolmenu = array(
            array( 'icon' => 'save.gif', 'title' => $_LANG['SAVE'], 'link' => 'javascript:document.addform.submit();' ),
            array( 'icon' => 'cancel.gif', 'title' => $_LANG['CANCEL'], 'link' => 'javascript:history.go(-1);' )
        );

        cpToolMenu($toolmenu);
        
        if ($do == 'edit') {
            $mod = cmsCron::getJobById($id);
            if (!$mod) { cmsCore::error404(); }
            
            echo '<h3>'. $_LANG['AD_EDIT_MISSION'] .'</h3>';
            cpAddPathway($mod['job_name'], 'index.php?view=cron&do=edit&id='. $mod['id']);
        } else {
            echo '<h3>'. $_LANG['AD_CREATE_CRON_MISSION'] .'</h3>';
            cpAddPathway($_LANG['AD_CREATE_CRON_MISSION'], 'index.php?view=cron&do=add');
            $mod = array();
	}
?>
<form action="index.php?view=cron" method="post" enctype="multipart/form-data" name="addform" id="addform">
    <input type="hidden" name="csrf_token" value="<?php echo cmsUser::getCsrfToken(); ?>" />
    
    <div style="width:650px;">
        <div class="form-group">
            <label><?php echo $_LANG['TITLE']; ?>:</label>
            <input type="text" class="form-control" name="job_name" value="<?php echo cmsCore::getArrVal($mod, 'job_name', ''); ?>" />
            <div class="help-block"><?php echo $_LANG['AD_ONLY_LATIN']; ?></div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['DESCRIPTION']; ?>:</label>
            <input type="text" class="form-control" name="comment" maxlength="200" value="<?php echo htmlspecialchars(cmsCore::getArrVal($mod, 'comment', '')); ?>" />
            <div class="help-block"><?php echo $_LANG['AD_ONLY_200_SIMBOLS']; ?></div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_MISSION_ON']; ?>:</label>
            <div class="btn-group" data-toggle="buttons" style="float:right;">
                <label class="btn btn-default <?php if (cmsCore::getArrVal($mod, 'is_enabled')) { echo 'active'; } ?>">
                    <input type="radio" name="enabled" <?php if ($mod['is_enabled']) { echo 'checked="checked"'; } ?> value="1" /> <?php echo $_LANG['YES']; ?>
                </label>
                <label class="btn btn-default <?php if (!cmsCore::getArrVal($mod, 'is_enabled')) { echo 'active'; } ?>">
                    <input type="radio" name="enabled" <?php if (!$mod['is_enabled']) { echo 'checked="checked"'; } ?> value="0" /> <?php echo $_LANG['NO']; ?>
                </label>
            </div>
            <div class="help-block"><?php echo $_LANG['AD_MISSION_OFF']; ?></div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_MISSION_INTERVAL']; ?> (<?php echo $_LANG['HOUR1']; ?>):</label>
            <input type="number" class="form-control" name="job_interval" min="0" value="<?php echo cmsCore::getArrVal($mod, 'job_interval', ''); ?>" /> 
            <div class="help-block"><?php echo $_LANG['AD_MISSION_PERIOD']; ?></div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_PHP_FILE']; ?>:</label>
            <input type="text" class="form-control" name="custom_file" maxlength="250" value="<?php echo cmsCore::getArrVal($mod, 'custom_file', ''); ?>" /> 
            <div class="help-block"><?php echo $_LANG['AD_EXAMPLE'] ; ?>: <b>includes/myphp/test.php</b></div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_COMPONENT']; ?>:</label>
            <input type="text" class="form-control" name="component" maxlength="250" value="<?php echo cmsCore::getArrVal($mod, 'component', ''); ?>" /> 
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_METHOD']; ?>:</label>
            <input type="text" class="form-control" name="model_method" maxlength="250" value="<?php echo cmsCore::getArrVal($mod, 'model_method', ''); ?>" /> 
        </div>
        
        <div class="form-group">
            <label><?php echo icms_ucfirst($_LANG['AD_CLASS']); ?></label>
            <input type="text" class="form-control" name="class_name" maxlength="50" value="<?php echo cmsCore::getArrVal($mod, 'class_name', ''); ?>" />
            <div class="help-block">
                <span style="color:#666;font-family: mono"><?php echo $_LANG['AD_FILE_CLASS']; ?></span>, <?php echo $_LANG['AD_EXAMPLE']; ?> <b>actions|cmsActions</b>&nbsp;<?php echo $_LANG['OR']; ?><br/>
                <span style="color:#666;font-family: mono"><?php echo $_LANG['AD_CLASS']; ?></span>, <?php echo $_LANG['AD_EXAMPLE']; ?> <b>cmsDatabase</b>
            </div>
        </div>
        
        <div class="form-group">
            <label><?php echo $_LANG['AD_CLASS_METHOD']; ?>:</label>
            <input type="text" class="form-control" name="class_method" maxlength="50" value="<?php echo cmsCore::getArrVal($mod, 'class_method', ''); ?>" /> 
        </div>
    </div>
    
    <div>
        <?php if ($do == 'edit') { ?>
            <input type="hidden" name="do" value="update" />
            <input type="submit" class="btn btn-primary" name="add_mod" value="<?php echo $_LANG['AD_SAVE_CRON_MISSION']; ?>" />
        <?php } else { ?>
            <input type="hidden" name="do" value="submit" />
            <input type="submit" class="btn btn-primary" name="add_mod" value="<?php echo $_LANG['AD_CREATE_CRON_MISSION'] ; ?>" />
        <?php } ?>
        
        <input type="button" class="btn btn-default" name="back2" value="<?php echo $_LANG['CANCEL']; ?>" onclick="window.history.back();" />
          
        <?php
            if ($do == 'edit') {
                echo '<input type="hidden" name="id" value="'. $mod['id'] .'" />';
            }
        ?>
        </div>
</form>
<?php
   }
}
Beispiel #2
0
function applet_cron()
{
    cmsCore::loadClass('cron');
    global $_LANG;
    global $adminAccess;
    if (!cmsUser::isAdminCan('admin/config', $adminAccess)) {
        cpAccessDenied();
    }
    $GLOBALS['cp_page_title'] = $_LANG['AD_CRON_MISSION'];
    cpAddPathway($_LANG['AD_SITE_SETTING'], 'index.php?view=config');
    cpAddPathway($_LANG['AD_CRON_MISSION'], 'index.php?view=cron');
    $do = cmsCore::request('do', 'str', 'list');
    $id = cmsCore::request('id', 'int', '0');
    if ($do == 'list') {
        $toolmenu = array(array('icon' => 'new.gif', 'title' => $_LANG['AD_CREATE_CRON_MISSION'], 'link' => '?view=cron&do=add'));
        cpToolMenu($toolmenu);
        $items = cmsCron::getJobs(false);
        $tpl_file = 'admin/cron.php';
        $tpl_dir = file_exists(TEMPLATE_DIR . $tpl_file) ? TEMPLATE_DIR : DEFAULT_TEMPLATE_DIR;
        include $tpl_dir . $tpl_file;
    }
    if ($do == 'show') {
        if ($id) {
            cmsCron::jobEnabled($id, true);
        }
        echo '1';
        exit;
    }
    if ($do == 'hide') {
        if ($id) {
            cmsCron::jobEnabled($id, false);
        }
        echo '1';
        exit;
    }
    if ($do == 'delete') {
        if ($id) {
            cmsCron::removeJobById($id);
        }
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'execute') {
        if ($id) {
            $job_result = cmsCron::executeJobById($id);
        }
        if ($job_result) {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_SUCCESS'], 'success');
        } else {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_ERROR'], 'error');
        }
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'submit') {
        if (!cmsUser::checkCsrfToken()) {
            cmsCore::error404();
        }
        $job_name = cmsCore::request('job_name', 'str');
        $comment = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled = cmsCore::request('enabled', 'int');
        $component = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file = cmsCore::request('custom_file', 'str');
        $custom_file = mb_stripos($custom_file, 'image/') || mb_stripos($custom_file, 'upload/') || mb_stripos($custom_file, 'cache/') ? '' : $custom_file;
        $custom_file = preg_replace('/\\.+\\//', '', $custom_file);
        $class_name = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');
        cmsCron::registerJob($job_name, array('interval' => $job_interval, 'component' => $component, 'model_method' => $model_method, 'comment' => $comment, 'custom_file' => $custom_file, 'enabled' => $enabled, 'class_name' => $class_name, 'class_method' => $class_method));
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'update') {
        if (!cmsUser::checkCsrfToken()) {
            cmsCore::error404();
        }
        if (!$id) {
            cmsCore::halt();
        }
        $job_name = cmsCore::request('job_name', 'str');
        $comment = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled = cmsCore::request('enabled', 'int');
        $component = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file = cmsCore::request('custom_file', 'str');
        $custom_file = mb_stripos($custom_file, 'image/') || mb_stripos($custom_file, 'upload/') || mb_stripos($custom_file, 'cache/') ? '' : $custom_file;
        $custom_file = preg_replace('/\\.+\\//', '', $custom_file);
        $class_name = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');
        cmsCron::updateJob($id, array('job_name' => $job_name, 'job_interval' => $job_interval, 'component' => $component, 'model_method' => $model_method, 'comment' => $comment, 'custom_file' => $custom_file, 'is_enabled' => $enabled, 'class_name' => $class_name, 'class_method' => $class_method));
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'edit' || $do == 'add') {
        $toolmenu = array(array('icon' => 'save.gif', 'title' => $_LANG['SAVE'], 'link' => 'javascript:document.addform.submit();'), array('icon' => 'cancel.gif', 'title' => $_LANG['CANCEL'], 'link' => 'javascript:history.go(-1);'));
        cpToolMenu($toolmenu);
        if ($do == 'edit') {
            $mod = cmsCron::getJobById($id);
            echo '<h3>' . $_LANG['AD_EDIT_MISSION'] . '</h3>';
            cpAddPathway($mod['job_name'], 'index.php?view=cron&do=edit&id=' . $mod['id']);
        } else {
            echo '<h3>' . $_LANG['AD_CREATE_CRON_MISSION'] . '</h3>';
            cpAddPathway($_LANG['AD_CREATE_CRON_MISSION'], 'index.php?view=cron&do=add');
        }
        ?>

    <form action="index.php?view=cron" method="post" enctype="multipart/form-data" name="addform" id="addform">
        <input type="hidden" name="csrf_token" value="<?php 
        echo cmsUser::getCsrfToken();
        ?>
" />
        <table width="750" border="0" cellpadding="0" cellspacing="10" class="proptable">
            <tr>
                <td width="300" valign="middle">
                    <strong><?php 
        echo $_LANG['TITLE'];
        ?>
:</strong><br/>
                    <span class="hinttext"><?php 
        echo $_LANG['AD_ONLY_LATIN'];
        ?>
</span>
                </td>
                <td width="" valign="middle">
                    <input name="job_name" type="text" style="width:220px" value="<?php 
        echo @$mod['job_name'];
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['DESCRIPTION'];
        ?>
: </strong><br/>
                    <span class="hinttext"><?php 
        echo $_LANG['AD_ONLY_200_SIMBOLS'];
        ?>
</span>
                </td>
                <td valign="middle">
                    <input name="comment" type="text" maxlength="200" style="width:400px" value="<?php 
        echo htmlspecialchars($mod['comment']);
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_MISSION_ON'];
        ?>
 </strong><br/>
                    <span class="hinttext"><?php 
        echo $_LANG['AD_MISSION_OFF'];
        ?>
</span>
                </td>
                <td valign="middle">
                    <label>
                        <input name="enabled" type="radio" value="1" <?php 
        if ($mod['is_enabled']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        echo $_LANG['YES'];
        ?>
                    </label>
                    <label>
                        <input name="enabled" type="radio" value="0"  <?php 
        if (!$mod['is_enabled']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        echo $_LANG['NO'];
        ?>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_MISSION_INTERVAL'];
        ?>
:</strong><br/>
                    <span class="hinttext"><?php 
        echo $_LANG['AD_MISSION_PERIOD'];
        ?>
</span>
                </td>
                <td valign="middle">
                    <input name="job_interval" type="text" maxlength="4" style="width:50px" value="<?php 
        echo @$mod['job_interval'];
        ?>
" /> <?php 
        echo $_LANG['HOUR1'] . '.';
        ?>
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_PHP_FILE'];
        ?>
 </strong><br/>
                    <span class="hinttext"><?php 
        echo $_LANG['AD_EXAMPLE'];
        ?>
: <strong>includes/myphp/test.php</strong></span><br/>
                </td>
                <td valign="middle">
                    <input name="custom_file" type="text" maxlength="250" style="width:220px" value="<?php 
        echo @$mod['custom_file'];
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_COMPONENT'];
        ?>
: </strong><br/>
                </td>
                <td valign="middle">
                    <input name="component" type="text" maxlength="250" style="width:220px" value="<?php 
        echo @$mod['component'];
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_METHOD'];
        ?>
 </strong><br/>
                </td>
                <td valign="middle">
                    <input name="model_method" type="text" maxlength="250" style="width:220px" value="<?php 
        echo @$mod['model_method'];
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo icms_ucfirst($_LANG['AD_CLASS']);
        ?>
</strong><br/>
                    <span class="hinttext">
                        <span style="color:#666;font-family: mono"><?php 
        echo $_LANG['AD_FILE_CLASS'];
        ?>
</span>, <?php 
        echo $_LANG['AD_EXAMPLE'];
        ?>
 <strong>actions|cmsActions</strong>&nbsp;<?php 
        echo $_LANG['OR'];
        ?>
<br/>
                        <span style="color:#666;font-family: mono"><?php 
        echo $_LANG['AD_CLASS'];
        ?>
</span>, <?php 
        echo $_LANG['AD_EXAMPLE'];
        ?>
 <strong>cmsDatabase</strong>
                    </span>
                </td>
                <td valign="top">
                    <input name="class_name" type="text" maxlength="50" style="width:220px" value="<?php 
        echo @$mod['class_name'];
        ?>
" />
                </td>
            </tr>
            <tr>
                <td width="" valign="middle">
                    <strong><?php 
        echo $_LANG['AD_CLASS_METHOD'];
        ?>
 </strong><br/>
                </td>
                <td valign="middle">
                    <input name="class_method" type="text" maxlength="50" style="width:220px" value="<?php 
        echo @$mod['class_method'];
        ?>
" />
                </td>
            </tr>
        </table>
        <p>
		  <?php 
        if ($do == 'edit') {
            ?>
	          <input name="do" type="hidden" id="do" value="update" />
	          <input name="add_mod" type="submit" id="add_mod" value="<?php 
            echo $_LANG['AD_SAVE_CRON_MISSION'];
            ?>
" />
		  <?php 
        } else {
            ?>
	          <input name="do" type="hidden" id="do" value="submit" />
	          <input name="add_mod" type="submit" id="add_mod" value="<?php 
            echo $_LANG['AD_CREATE_CRON_MISSION'];
            ?>
" />
		  <?php 
        }
        ?>
          <span style="margin-top:15px">
          <input name="back2" type="button" id="back2" value="<?php 
        echo $_LANG['CANCEL'];
        ?>
" onclick="window.history.back();" />
          </span>
        <?php 
        if ($do == 'edit') {
            echo '<input name="id" type="hidden" value="' . $mod['id'] . '" />';
        }
        ?>
        </p>
      </form>
	<?php 
    }
}
Beispiel #3
0
function applet_cron()
{
    cmsCore::loadClass('cron');
    global $_LANG;
    global $adminAccess;
    if (!cmsUser::isAdminCan('admin/config', $adminAccess)) {
        cpAccessDenied();
    }
    cmsCore::c('page')->setTitle($_LANG['AD_CRON_MISSION']);
    cpAddPathway($_LANG['AD_SITE_SETTING'], 'index.php?view=config');
    cpAddPathway($_LANG['AD_CRON_MISSION'], 'index.php?view=cron');
    $do = cmsCore::request('do', 'str', 'list');
    $id = cmsCore::request('id', 'int', '0');
    if ($do == 'list') {
        $toolmenu = array(array('icon' => 'new.gif', 'title' => $_LANG['AD_CREATE_CRON_MISSION'], 'link' => '?view=cron&do=add'));
        cpToolMenu($toolmenu);
        $fields = array(array('title' => 'id', 'field' => 'id', 'width' => '40'), array('title' => $_LANG['TITLE'], 'field' => 'job_name', 'width' => '80', 'link' => '?view=cron&do=edit&id=%id%'), array('title' => $_LANG['DESCRIPTION'], 'field' => 'comment', 'width' => ''), array('title' => $_LANG['AD_MISSION_INTERVAL'], 'field' => 'job_interval', 'width' => '30', 'prc' => function ($interval) {
            global $_LANG;
            return $interval . ' ' . $_LANG['HOUR'];
        }), array('title' => $_LANG['AD_LAST_START'], 'field' => 'job_run_date', 'width' => '150'), array('title' => $_LANG['AD_IS_ACTIVE'], 'field' => 'is_enabled', 'width' => '50', 'published' => true));
        $actions = array(array('title' => $_LANG['AD_PERFORM_TASK'], 'icon' => 'play.gif', 'confirm' => $_LANG['AD_PERFORM_TASK'] . ' %job_name%?', 'link' => '?view=cron&do=execute&id=%id%'), array('title' => $_LANG['EDIT'], 'icon' => 'edit.gif', 'link' => '?view=cron&do=edit&id=%id%'), array('title' => $_LANG['DELETE'], 'icon' => 'delete.gif', 'confirm' => $_LANG['AD_IF_COMENT_DELETE'], 'link' => '?view=cron&do=delete&id=%id%'));
        cpListTable('cms_cron_jobs', $fields, $actions, '1=1', 'job_run_date ASC');
    }
    if ($do == 'show') {
        if ($id) {
            cmsCron::jobEnabled($id, true);
        }
        cmsCore::halt('1');
    }
    if ($do == 'hide') {
        if ($id) {
            cmsCron::jobEnabled($id, false);
        }
        cmsCore::halt('1');
    }
    if ($do == 'delete') {
        if ($id) {
            cmsCron::removeJobById($id);
        }
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'execute') {
        if ($id) {
            $job_result = cmsCron::executeJobById($id);
        }
        if ($job_result) {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_SUCCESS'], 'success');
        } else {
            cmsCore::addSessionMessage($_LANG['AD_MISSION_ERROR'], 'error');
        }
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'submit') {
        if (!cmsUser::checkCsrfToken()) {
            cmsCore::error404();
        }
        $job_name = cmsCore::request('job_name', 'str');
        $comment = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled = cmsCore::request('enabled', 'int');
        $component = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file = cmsCore::request('custom_file', 'str');
        $custom_file = mb_stripos($custom_file, 'image') || mb_stripos($custom_file, 'upload') || mb_stripos($custom_file, 'cache') ? '' : $custom_file;
        $custom_file = preg_replace('/\\.+\\//', '', $custom_file);
        $class_name = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');
        cmsCron::registerJob($job_name, array('interval' => $job_interval, 'component' => $component, 'model_method' => $model_method, 'comment' => $comment, 'custom_file' => $custom_file, 'enabled' => $enabled, 'class_name' => $class_name, 'class_method' => $class_method));
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'update') {
        if (!cmsUser::checkCsrfToken()) {
            cmsCore::error404();
        }
        if (!$id) {
            cmsCore::halt();
        }
        $job_name = cmsCore::request('job_name', 'str');
        $comment = cmsCore::request('comment', 'str');
        $job_interval = cmsCore::request('job_interval', 'int');
        $enabled = cmsCore::request('enabled', 'int');
        $component = cmsCore::request('component', 'str');
        $model_method = cmsCore::request('model_method', 'str');
        $custom_file = cmsCore::request('custom_file', 'str');
        $custom_file = mb_stripos($custom_file, 'image') || mb_stripos($custom_file, 'upload') || mb_stripos($custom_file, 'cache') ? '' : $custom_file;
        $custom_file = preg_replace('/\\.+\\//', '', $custom_file);
        $class_name = cmsCore::request('class_name', 'str');
        $class_method = cmsCore::request('class_method', 'str');
        cmsCron::updateJob($id, array('job_name' => $job_name, 'job_interval' => $job_interval, 'component' => $component, 'model_method' => $model_method, 'comment' => $comment, 'custom_file' => $custom_file, 'is_enabled' => $enabled, 'class_name' => $class_name, 'class_method' => $class_method));
        cmsCore::redirect('index.php?view=cron');
    }
    if ($do == 'edit' || $do == 'add') {
        $toolmenu = array(array('icon' => 'save.gif', 'title' => $_LANG['SAVE'], 'link' => 'javascript:document.addform.submit();'), array('icon' => 'cancel.gif', 'title' => $_LANG['CANCEL'], 'link' => 'javascript:history.go(-1);'));
        cpToolMenu($toolmenu);
        if ($do == 'edit') {
            $mod = cmsCron::getJobById($id);
            if (!$mod) {
                cmsCore::error404();
            }
            echo '<h3>' . $_LANG['AD_EDIT_MISSION'] . '</h3>';
            cpAddPathway($mod['job_name'], 'index.php?view=cron&do=edit&id=' . $mod['id']);
        } else {
            echo '<h3>' . $_LANG['AD_CREATE_CRON_MISSION'] . '</h3>';
            cpAddPathway($_LANG['AD_CREATE_CRON_MISSION'], 'index.php?view=cron&do=add');
            $mod = array();
        }
        cmsCore::c('page')->initTemplate('applets', 'cron_edit')->assign('do', $do)->assign('mod', $mod)->display();
    }
}