seeddms-code/views/bootstrap/class.SchedulerTaskMgr.php

318 lines
11 KiB
PHP

<?php
/**
* Implementation of SchedulerTaskMgr view
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2013 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Include parent class
*/
require_once("class.Bootstrap.php");
/**
* Class which outputs the html page for SchedulerTaskMgr view
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2013 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_View_SchedulerTaskMgr extends SeedDMS_Bootstrap_Style {
function js() { /* {{{ */
header('Content-Type: application/javascript');
?>
$(document).ready( function() {
$('body').on('click', '.addtask', function(ev){
ev.preventDefault();
$('#editaddtask.ajax').trigger('update', {extension: $(this).data('extension'), task: $(this).data('task')});
});
$('body').on('click', '.listtasks', function(ev){
ev.preventDefault();
$('#listtasks.ajax').trigger('update', {extension: $(this).data('extension'), task: $(this).data('task')});
});
$('body').on('click', '.edittask', function(ev){
ev.preventDefault();
$('#editaddtask.ajax').trigger('update', {taskid: $(this).data('id'), action: $(this).data('action')});
});
$('#listtasks.ajax').trigger('update', {});
});
<?php
} /* }}} */
public function form() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$extname = $this->params['extname'];
$taskname = $this->params['taskname'];
if($extname && $taskname) {
$taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$extname][$taskname];
if(method_exists($taskobj, 'getAdditionalParams'))
$additionalparams = $taskobj->getAdditionalParams();
else
$additionalparams = null;
?>
<form action="../op/op.SchedulerTaskMgr.php" method="post" class="form-horizontal">
<?= createHiddenFieldWithKey('addtask') ?>
<input type="hidden" name="action" value="addtask">
<input type="hidden" name="extension" value="<?= $extname ?>">
<input type="hidden" name="task" value="<?= $taskname ?>">
<div class="control-group">
<label class="control-label" for="extension"><?= getMLText("scheduler_class");?>:</label>
<div class="controls">
<span class="input uneditable-input"><?= $extname ?>::<?= $taskname ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="name"><?php printMLText("task_name");?>:</label>
<div class="controls">
<input type="text" id="name" name="name" value="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="description"><?php printMLText("task_description");?>:</label>
<div class="controls">
<input type="text" id="description" name="description" value="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="frequency"><?php printMLText("task_frequency");?>:</label>
<div class="controls">
<input type="text" id="frequency" name="frequency" value="">
</div>
</div>
<?php
if($additionalparams) {
foreach($additionalparams as $param) {
switch($param['type']) {
default:
?>
<div class="control-group">
<label class="control-label" for="params_<?= $param['name'] ?>"><?php printMLText('task_'.$extname."_".$taskname."_".$param['name']);?>:</label>
<div class="controls">
<input type="text" id="params_<?= $param['name'] ?>" name="params[<?= $param['name'] ?>]" value="">
</div>
</div>
<?php
break;
}
}
}
?>
<div class="control-group">
<label class="control-label" for="login"></label>
<div class="controls">
<button type="submit" class="btn"><i class="icon-save"></i> <?php printMLText("save")?></button>
</div>
</div>
</form>
<?php
}
} /* }}} */
public function edittask() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$scheduler = $this->params['scheduler'];
$taskid = $this->params['taskid'];
$task = $scheduler->getTask($taskid);
$taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()];
?>
<form action="../op/op.SchedulerTaskMgr.php" method="post" class="form-horizontal">
<?= createHiddenFieldWithKey('edittask') ?>
<input type="hidden" name="action" value="edittask">
<input type="hidden" name="taskid" value="<?= $taskid ?>">
<input type="hidden" name="extension" value="<?= $task->getExtension() ?>">
<input type="hidden" name="task" value="<?= $task->getTask() ?>">
<div class="control-group">
<label class="control-label" for="extension"><?= getMLText("scheduler_class");?>:</label>
<div class="controls">
<span class="input uneditable-input"><?= $task->getExtension() ?>::<?= $task->getTask() ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="name"><?php printMLText("task_name");?>:</label>
<div class="controls">
<input type="text" id="name" name="name" value="<?= $task->getName() ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="description"><?php printMLText("task_description");?>:</label>
<div class="controls">
<input type="text" id="description" name="description" value="<?= $task->getDescription() ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="frequency"><?php printMLText("task_frequency");?>:</label>
<div class="controls">
<input type="text" id="frequency" name="frequency" value="<?= $task->getFrequency() ?>">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="disabled" value="1"<?= ($task->getDisabled() ? ' checked' : '') ?>> <?= getMLText('task_disabled'); ?>
</label>
</div>
</div>
<?php
if($additionalparams = $taskobj->getAdditionalParams()) {
foreach($additionalparams as $param) {
switch($param['type']) {
default:
?>
<div class="control-group">
<label class="control-label" for="params_<?= $param['name'] ?>"><?php printMLText('task_'.$task->getExtension()."_".$task->getTask()."_".$param['name']);?>:</label>
<div class="controls">
<input type="text" id="params_<?= $param['name'] ?>" name="params[<?= $param['name'] ?>]" value="<?= $task->getParameter()[$param['name']] ?>">
</div>
</div>
<?php
break;
}
}
}
?>
<div class="control-group">
<label class="control-label" for="login"></label>
<div class="controls">
<button type="submit" class="btn"><i class="icon-save"></i> <?php printMLText("save")?></button>
</div>
</div>
</form>
<?php
} /* }}} */
public function tasklist() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$extname = $this->params['extname'];
$taskname = $this->params['taskname'];
$scheduler = $this->params['scheduler'];
if($extname && $taskname)
$tasks = $scheduler->getTasksByExtension($extname, $taskname);
else
$tasks = $scheduler->getTasks();
if(!$tasks)
return;
$this->contentHeading(getMLText("scheduler_class_tasks"));
echo "<table class=\"table _table-condensed\">\n";
print "<thead>\n<tr>\n";
print "<th>".getMLText('scheduler_class')."</th>\n";
print "<th>".getMLText('task_name')."</th>\n";
print "<th>".getMLText('task_description')."</th>\n";
print "<th>".getMLText('task_frequency')."</th>\n";
print "<th>".getMLText('task_next_run')."</th>\n";
print "<th>".getMLText('task_last_run')."</th>\n";
print "<th></th>\n";
print "</tr></thead><tbody>\n";
foreach($tasks as $task) {
echo "<tr".(!$task->getDisabled() ? " class=\"success\"" : "").">";
echo "<td>";
echo $task->getExtension()."::".$task->getTask();
echo "</td>";
echo "<td>";
echo $task->getName();
echo "</td>";
echo "<td width=\"100%\">";
echo $task->getDescription();
echo "</td>";
echo "<td>";
echo $task->getFrequency();
echo "</td>";
echo "<td>";
echo $task->getNextRun();
echo "</td>";
echo "<td>";
echo $task->getLastRun();
echo "</td>";
echo "<td>";
print "<div class=\"list-action\">";
print "<a class=\"edittask\" data-action=\"edittask\" data-id=\"".$task->getID()."\" href=\"../out/out.SchedulerTaskMgr.php?action=edittask\" title=\"".getMLText("edit_task")."\"><i class=\"icon-edit\"></i></a>";
print "</div>";
echo "</td>";
echo "</tr>";
}
echo "</tbody></table>\n";
} /* }}} */
function show() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$extname = $this->params['extname'];
$taskname = $this->params['taskname'];
$scheduler = $this->params['scheduler'];
$this->htmlStartPage(getMLText("admin_tools"));
$this->globalNavigation();
$this->contentStart();
$this->pageNavigation(getMLText("admin_tools"), "admin_tools");
$this->contentHeading(getMLText("scheduler_task_mgr"));
?>
<div class="row-fluid">
<div class="span6">
<?php
if(!empty($GLOBALS['SEEDDMS_SCHEDULER']['tasks'])) {
echo "<table class=\"table _table-condensed\">\n";
print "<thead>\n<tr>\n";
print "<th>".getMLText('scheduler_class')."</th>\n";
print "<th>".getMLText('scheduler_class_description')."</th>\n";
print "<th>".getMLText('scheduler_class_parameter')."</th>\n";
print "<th></th>\n";
print "</tr></thead><tbody>\n";
$errmsgs = array();
foreach($GLOBALS['SEEDDMS_SCHEDULER']['tasks'] as $extname=>$tasks) {
foreach($tasks as $taskname=>$task) {
echo "<tr>";
echo "<td>";
echo $extname."::".$taskname;
echo "</td>";
echo "<td width=\"100%\">";
echo $task->getDescription();
echo "</td>";
echo "<td>";
$params = $task->getAdditionalParams();
foreach($params as $param)
$k[] = $param['name'];
echo implode(', ', $k);
echo "</td>";
echo "<td>";
print "<div class=\"list-action\">";
$t = $scheduler->getTasksByExtension($extname, $taskname);
if($t) {
print "<a class=\"listtasks\" data-extension=\"".$extname."\" data-task=\"".$taskname."\" href=\"../out/out.SchedulerTaskMgr.php?extension=".$extname."&task=".$taskname."\" title=\"".getMLText("list_tasks")."\"><i class=\"icon-list\"></i></a>";
}
print "<a class=\"addtask\" data-extension=\"".$extname."\" data-task=\"".$taskname."\" href=\"../out/out.SchedulerTaskMgr.php?extension=".$extname."&task=".$taskname."\" title=\"".getMLText("add_task")."\"><i class=\"icon-plus\"></i></a>";
print "</div>";
echo "</td>";
echo "</tr>";
}
}
echo "</tbody></table>\n";
}
?>
<div id="listtasks" class="ajax" data-view="SchedulerTaskMgr" data-action="tasklist"></div>
</div>
<div class="span6">
<div id="editaddtask" class="ajax" data-view="SchedulerTaskMgr" data-action="form"></div>
</div>
</div>
<?php
$this->contentEnd();
$this->htmlEndPage();
} /* }}} */
}
?>