Files
IPB/upload/sources/action_admin/task_manager.php
T
2025-12-19 00:24:35 -08:00

944 lines
30 KiB
PHP

<?php
/*
+--------------------------------------------------------------------------
| Invision Power Board 2.2.2
| =============================================
| by Matthew Mecham
| (c) 2001 - 2006 Invision Power Services, Inc.
| http://www.invisionpower.com
| =============================================
| Web: http://www.invisionboard.com
| http://www.ibresource.ru/products/invisionpowerboard/
| Time: Monday 05th of March 2007 10:10:54 PM
| Release: e3790216629e5a2aaf37070b32237f06
| Licence Info: http://www.invisionboard.com/?license
| http://www.ibresource.ru/license
+---------------------------------------------------------------------------
| INVISION POWER BOARD ÍÅ ßÂËßÅÒÑß ÁÅÑÏËÀÒÍÛÌ ÏÐÎÃÐÀÌÌÍÛÌ ÎÁÅÑÏÅ×ÅÍÈÅÌ!
| Ïðàâà íà ÏÎ ïðèíàäëåæàò Invision Power Services
| Ïðàâà íà ïåðåâîä IBResource (http://www.ibresource.ru)
+---------------------------------------------------------------------------
| > $Date: 2006-09-22 05:28:54 -0500 (Fri, 22 Sep 2006) $
| > $Revision: 567 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > Task Manager
| > Module written by Matt Mecham
| > Date started: 27th January 2004
|
| > Module Version Number: 1.0.0
| > DBA Checked: Tue 25th May 2004
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "<h1>Íåêîððåêòíûé àäðåñ</h1>Âû íå èìååòå äîñòóïà ê ýòîìó ôàéëó íàïðÿìóþ. Åñëè âû íåäàâíî îáíîâëÿëè ôîðóì, âû äîëæíû îáíîâèòü âñå ñîîòâåòñòâóþùèå ôàéëû.";
exit();
}
class ad_task_manager
{
# Global
var $ipsclass;
var $functions = "";
/**
* Section title name
*
* @var string
*/
var $perm_main = "tools";
/**
* Section title name
*
* @var string
*/
var $perm_child = "task";
function auto_run()
{
$this->ipsclass->form_code = "{$this->ipsclass->form_code}";
//-----------------------------------------
// Require and RUN !! THERES A BOMB
//-----------------------------------------
require_once( ROOT_PATH.'sources/lib/func_taskmanager.php' );
$this->functions = new func_taskmanager();
$this->functions->ipsclass =& $this->ipsclass;
//-----------------------------------------
// Load skin
//-----------------------------------------
$this->html = $this->ipsclass->acp_load_template('cp_skin_taskmanager');
//-----------------------------------------
// Continue
//-----------------------------------------
$this->ipsclass->admin->page_detail = "Ýòà ñåêöèÿ ñîäåðæèò âñå âàøè óñòàíîâëåííûå çàäà÷è.<br />Ïîæàëóéñòà, ó÷òèòå, ÷òî âñå ýòè çàäà÷è çàïóñêàþòñÿ òîëüêî òîãäà, êîãäà âàø ôîðóì äîñòóïåí ïîñåòèòåëÿì, ñëåäóþùèé çàïóñê ïðîèñõîäèò òîëüêî ïðè âûçîâå ôîðóìà.";
$this->ipsclass->admin->page_title = "Óïðàâëåíèå çàäà÷àìè";
$this->ipsclass->admin->nav[] = array( $this->ipsclass->form_code, 'Ñïèñîê çàäà÷' );
//-----------------------------------------
// Using "do"?
//-----------------------------------------
if ( isset($this->ipsclass->input['j_do']) AND $this->ipsclass->input['j_do'] )
{
$this->ipsclass->input['code'] = $this->ipsclass->input['j_do'];
}
else if ( isset($this->ipsclass->input['do']) AND $this->ipsclass->input['do'] )
{
$this->ipsclass->input['code'] = $this->ipsclass->input['do'];
}
//-----------------------------------------
// What to do...
//-----------------------------------------
switch($this->ipsclass->input['code'])
{
case 'task_edit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->task_form('edit');
break;
case 'task_add':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->task_form('add');
break;
case 'task_edit_do':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->task_do_save('edit');
break;
case 'task_add_do':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->task_do_save('add');
break;
case 'task_delete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->task_delete_task();
break;
case 'task_run_now':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':runnow' );
$this->task_run_task();
break;
case 'task_unlock':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->task_unlock();
break;
case 'log':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':log' );
$this->task_log_setup();
break;
case 'showlog':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':log' );
$this->task_log_show();
break;
case 'deletelog':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->task_log_delete();
break;
case 'master_xml_export':
$this->master_xml_export();
break;
case 'task_rebuild_xml':
$this->task_rebuild_xml();
break;
default:
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->task_show_tasks();
break;
}
}
/*-------------------------------------------------------------------------*/
// Rebuild XML
/*-------------------------------------------------------------------------*/
function task_rebuild_xml()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$file = ROOT_PATH . 'resources/tasks.xml';
$inserted = 0;
$updated = 0;
$tasks = array();
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! file_exists( $file ) )
{
$this->ipsclass->main_msg = "Ôàéë $file íå íàéäåí.";
$this->show_intro();
}
//-----------------------------------------
// Get current task info
//-----------------------------------------
$this->ipsclass->DB->build_query( array( 'select' => '*',
'from' => 'task_manager' ) );
$this->ipsclass->DB->exec_query();
while( $row = $this->ipsclass->DB->fetch_row() )
{
$tasks[ $row['task_key'] ] = $row;
}
//-----------------------------------------
// Get XML
//-----------------------------------------
require_once( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
//-----------------------------------------
// Get XML file (CSS/WRAPPERS)
//-----------------------------------------
$skin_content = implode( "", file($file) );
//-----------------------------------------
// Unpack the datafile (TEMPLATES)
//-----------------------------------------
$xml->lite_parser = 1;
$xml->xml_parse_document( $skin_content );
//-----------------------------------------
// TASKS
//-----------------------------------------
foreach( $xml->xml_array['export']['group']['row'] as $id => $entry )
{
$newrow = array();
$_key = $entry['task_key']['VALUE'];
foreach( $entry as $f => $data )
{
if ( $f == 'VALUE' or $f == 'task_id' )
{
continue;
}
if ( $f == 'task_cronkey' )
{
$entry[ $f ]['VALUE'] = $tasks[ $_key ]['task_cronkey'] ? $tasks[ $_key ]['task_cronkey'] : md5( uniqid( microtime() ) );
}
if ( $f == 'task_next_run' )
{
$entry[ $f ]['VALUE'] = $tasks[ $_key ]['task_next_run'] ? $tasks[ $_key ]['task_next_run'] : time();
}
$newrow[$f] = $entry[ $f ]['VALUE'];
}
if ( $tasks[ $_key ]['task_key'] )
{
$updated++;
$this->ipsclass->DB->do_update( 'task_manager', $newrow, "task_key='" . $tasks[ $_key ]['task_key'] . "'" );
}
else
{
$inserted++;
$this->ipsclass->DB->do_insert( 'task_manager', $newrow );
}
}
$this->ipsclass->main_msg = "$inserted çàäà÷ äîáàëåíî è $updated îáíîâëåíî.";
$this->task_show_tasks();
}
/*-------------------------------------------------------------------------*/
// Export Master XML
/*-------------------------------------------------------------------------*/
function master_xml_export()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$entry = array();
//-----------------------------------------
// Get XML class
//-----------------------------------------
require_once( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
$xml->doc_type = $this->ipsclass->vars['gb_char_set'];
$xml->xml_set_root( 'export', array( 'exported' => time() ) );
//-----------------------------------------
// Set group
//-----------------------------------------
$xml->xml_add_group( 'group' );
//-----------------------------------------
// Get templates...
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*',
'from' => 'task_manager' ) );
$this->ipsclass->DB->simple_exec();
while ( $r = $this->ipsclass->DB->fetch_row() )
{
$content = array();
//-----------------------------------------
// Sort the fields...
//-----------------------------------------
foreach( $r as $k => $v )
{
$content[] = $xml->xml_build_simple_tag( $k, $v );
}
$entry[] = $xml->xml_build_entry( 'row', $content );
}
$xml->xml_add_entry_to_group( 'group', $entry );
$xml->xml_format_document();
$doc = $xml->xml_document;
//-----------------------------------------
// Print to browser
//-----------------------------------------
$this->ipsclass->admin->show_download( $doc, 'tasks.xml', '', 0 );
}
/*-------------------------------------------------------------------------*/
// TASK LOG DELETE
/*-------------------------------------------------------------------------*/
function task_log_delete()
{
//-----------------------------------------
// SHOW 'EM
//-----------------------------------------
$prune = $this->ipsclass->input['task_prune'] ? $this->ipsclass->input['task_prune'] : 30;
$prune = time() - ( $prune * 86400 );
if ( $this->ipsclass->input['task_id'] != -1 )
{
$where = "log_title='".$this->ipsclass->input['task_id']."' AND log_date < $prune";
}
else
{
$where = "log_date < $prune";
}
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'task_logs', 'where' => $where ) );
$this->ipsclass->main_msg = 'Âûáðàííûå çàïèñè âûïîëíåííûõ çàäà÷ óäàëåíû';
$this->task_log_setup();
}
/*-------------------------------------------------------------------------*/
// TASK LOG SHOW
/*-------------------------------------------------------------------------*/
function task_log_show()
{
$this->ipsclass->admin->nav[] = array( '', 'Viewing Task Logs' );
//-----------------------------------------
// SHOW 'EM
//-----------------------------------------
$limit = $this->ipsclass->input['task_count'] ? $this->ipsclass->input['task_count'] : 30;
$limit = $limit > 150 ? 150 : intval($limit);
if ( $this->ipsclass->input['task_id'] != -1 )
{
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'task_logs', 'where' => "log_title='".$this->ipsclass->input['task_id']."'", 'order' => 'log_date DESC', 'limit' => array(0,$limit) ) );
}
else
{
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'task_logs', 'order' => 'log_date DESC', 'limit' => array(0,$limit) ) );
}
$this->ipsclass->DB->simple_exec();
$this->ipsclass->adskin->td_header[] = array( "Âûïîëíåííàÿ çàäà÷à" , "20%" );
$this->ipsclass->adskin->td_header[] = array( "Äàòà" , "35%" );
$this->ipsclass->adskin->td_header[] = array( "Èíôîðìàöèÿ", "45%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Âûáðàííûå çàïèñè æóðíàëà çàäà÷" );
if ( $this->ipsclass->DB->get_num_rows() )
{
while ( $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>{$row['log_title']}</b>",
$this->ipsclass->admin->get_date( $row['log_date'], 'SHORT' ),
"{$row['log_desc']}",
) );
}
}
else
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("<center>Íåò çàïèñåé</center>");
}
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// TASK LOG START
/*-------------------------------------------------------------------------*/
function task_log_setup()
{
$this->ipsclass->admin->nav[] = array( '', 'Ïðîñìîòð âûïîëíåííûõ çàäà÷' );
//-----------------------------------------
// Some set up
//-----------------------------------------
$tasks = array( 0 => array( -1, 'Âñå çàäà÷è' ) );
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'task_manager', 'order' => 'task_title' ) );
$this->ipsclass->DB->simple_exec();
while ( $pee = $this->ipsclass->DB->fetch_row() )
{
$tasks[] = array( $pee['task_title'], $pee['task_title'] );
}
//-----------------------------------------
// LAST FIVE ACTIONS
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'task_logs', 'order' => 'log_date DESC', 'limit' => array(0,5) ) );
$this->ipsclass->DB->simple_exec();
$this->ipsclass->adskin->td_header[] = array( "Âûïîëíåííàÿ çàäà÷à" , "20%" );
$this->ipsclass->adskin->td_header[] = array( "Äàòà Âðåìÿ" , "35%" );
$this->ipsclass->adskin->td_header[] = array( "Èíôîðìàöèÿ" , "45%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "5 ïîñëåäíèõ çàïóùåííûõ çàäà÷" );
if ( $this->ipsclass->DB->get_num_rows() )
{
while ( $row = $this->ipsclass->DB->fetch_row() )
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>{$row['log_title']}</b>",
$this->ipsclass->admin->get_date( $row['log_date'], 'SHORT' ),
"{$row['log_desc']}",
) );
}
}
else
{
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_basic("<center>Íåò çàïèñåé</center>");
}
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
//-----------------------------------------
// Show more...
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'act' , 'task' ),
2 => array( 'code' , 'showlog' ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "60%" );
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "40%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Ïðîñìîòð âûïîëíåííûõ çàäà÷" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Çàäà÷à</b>",
$this->ipsclass->adskin->form_dropdown( 'task_id', $tasks )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Ñêîëüêî âûâåñòè çàïèñåé?</b>",
$this->ipsclass->adskin->form_input( 'task_count', '30' )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form('Ïðîñìîòð');
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
//-----------------------------------------
// Delete...
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'act' , 'task' ),
2 => array( 'code' , 'deletelog' ),
4 => array( 'section', $this->ipsclass->section_code ),
) );
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "60%" );
$this->ipsclass->adskin->td_header[] = array( "&nbsp;" , "40%" );
$this->ipsclass->html .= $this->ipsclass->adskin->start_table( "Óäàëåíèå çàïèñåé" );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Çàäà÷à</b>",
$this->ipsclass->adskin->form_dropdown( 'task_id', $tasks )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Óäàëèòü âûïîëíåííûå çàäà÷è ñòàðøå, ÷åì (â äíÿõ):</b>",
$this->ipsclass->adskin->form_input( 'task_prune', '30' )
) );
$this->ipsclass->html .= $this->ipsclass->adskin->end_form('Óäàëèòü');
$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// UNLOCK TASK
/*-------------------------------------------------------------------------*/
function task_unlock()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$task_id = intval( $this->ipsclass->input['task_id'] );
$this->ipsclass->DB->do_update( 'task_manager', array( 'task_locked' => 0 ), "task_id=".$task_id );
$this->ipsclass->main_msg = 'Çàêðûòûå çàäà÷è óäàëåíû';
$this->task_show_tasks();
}
/*-------------------------------------------------------------------------*/
// RUN TASK
/*-------------------------------------------------------------------------*/
function task_run_task()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$task_id = intval( $this->ipsclass->input['task_id'] );
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $task_id )
{
$this->ipsclass->main_msg = 'Íå óêàçàí ID çàäà÷è, äåéñòâèå íå âûïîëíåíî';
$this->task_show_tasks();
}
$this_task = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'task_manager', 'where' => 'task_id='.$task_id ) );
if ( ! $this_task['task_id'] )
{
$this->ipsclass->main_msg = 'Íåò çàäà÷ äëÿ âûïîëíåíèÿ.';
$this->show_tasks();
}
if ( ! $this_task['task_enabled'] )
{
$this->ipsclass->main_msg = "Ýòà çàäà÷à îòêëþ÷åíà. Ïîæàëóéñòà, âêëþ÷èòå åå äî çàïóñêà.";
$this->task_show_tasks();
}
//-----------------------------------------
// Get new instance of functions
//-----------------------------------------
$func = new func_taskmanager();
$func->ipsclass =& $this->ipsclass;
//-----------------------------------------
// Locked?
//-----------------------------------------
if ( $this_task['task_locked'] > 0 )
{
$this->ipsclass->main_msg = "Ýòà çàäà÷à áûëà çàêðûòà â ". gmdate( 'j M Y - G:i', $this_task['task_locked'] ) ." è íå ìîæåò áûòü çàïóùåíà ïîêà Âû åå íå îòêðîåòå ñíîâà.";
$this->task_show_tasks();
}
$newdate = $func->generate_next_run($this_task);
$this->ipsclass->DB->do_update( 'task_manager', array( 'task_next_run' => $newdate, 'task_locked' => time() ), "task_id=".$this_task['task_id'] );
$func->save_next_run_stamp();
$func->root_path = ROOT_PATH;
if ( file_exists( $func->root_path.'sources/tasks/'.$this_task['task_file'] ) )
{
require_once( $func->root_path.'sources/tasks/'.$this_task['task_file'] );
$myobj = new task_item();
$myobj->register_class( $func );
$myobj->pass_task( $this_task );
$myobj->run_task();
$this->ipsclass->main_msg = 'Çàäà÷à óñïåøíî çàïóùåíà';
$this->task_show_tasks();
}
else
{
$this->ipsclass->main_msg = 'Íåâîçìîæíî íàéòè: '.$func->root_path.'sources/tasks/'.$this_task['task_file'];
$this->task_show_tasks();
}
}
/*-------------------------------------------------------------------------*/
// DELETE TASK
/*-------------------------------------------------------------------------*/
function task_delete_task()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$task_id = intval( $this->ipsclass->input['task_id'] );
//-----------------------------------------
// Check
//-----------------------------------------
$task = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'task_manager', 'where' => "task_id=$task_id" ) );
if ( $task['task_safemode'] and ! IN_DEV )
{
$this->ipsclass->main_msg = "Âû íå ìîæåòå óäàëèòü ýòó çàäà÷ó.";
$this->task_show_tasks();
return;
}
//-----------------------------------------
// Remove from the DB
//-----------------------------------------
$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'task_manager', 'where' => 'task_id='.$task_id ) );
$this->functions->save_next_run_stamp();
$this->ipsclass->main_msg = 'Çàäà÷à óäàëåíà!';
$this->task_show_tasks();
}
/*-------------------------------------------------------------------------*/
// DO SAVE
/*-------------------------------------------------------------------------*/
function task_do_save($type='edit')
{
//-----------------------------------------
// INIT
//-----------------------------------------
$task_id = intval($this->ipsclass->input['task_id']);
$task_cronkey = $this->ipsclass->input['task_cronkey'];
//-----------------------------------------
// Check...
//-----------------------------------------
if ( $type == 'edit' )
{
if ( ! $task_id )
{
$this->ipsclass->main_msg = 'Íå óêàçàí ID çàäà÷è, äåéñòâèå íå âûïîëíåíî';
$this->task_form();
}
}
if ( ! $this->ipsclass->input['task_title'] )
{
$this->ipsclass->main_msg = 'Âû äîëæíû ââåñòè íàçâàíèå çàäà÷è.';
$this->task_form();
}
if ( ! $this->ipsclass->input['task_file'] )
{
$this->ipsclass->main_msg = 'Âû äîëæíû ââåñòè èìÿ ôàéëà äëÿ èñïîëíåíèÿ';
$this->task_form();
}
//-----------------------------------------
// Check the task file...
//-----------------------------------------
$this->ipsclass->input['task_file'] = preg_replace( '#\.{1,}#s', '.', $this->ipsclass->input['task_file'] );
//-----------------------------------------
// Compile task
//-----------------------------------------
$save = array( 'task_title' => $this->ipsclass->input['task_title'],
'task_description' => $this->ipsclass->input['task_description'],
'task_file' => $this->ipsclass->input['task_file'],
'task_week_day' => $this->ipsclass->input['task_week_day'],
'task_month_day' => $this->ipsclass->input['task_month_day'],
'task_hour' => $this->ipsclass->input['task_hour'],
'task_minute' => $this->ipsclass->input['task_minute'],
'task_log' => $this->ipsclass->input['task_log'],
'task_cronkey' => $this->ipsclass->input['task_cronkey'] ? $task_cronkey : md5(microtime()),
'task_enabled' => $this->ipsclass->input['task_enabled']
);
if ( IN_DEV )
{
$save['task_key'] = $this->ipsclass->input['task_key'];
$save['task_safemode'] = $this->ipsclass->input['task_safemode'];
}
//-----------------------------------------
// Get next run date...
//-----------------------------------------
$save['task_next_run'] = $this->functions->generate_next_run( $save );
if ( $type == 'edit' )
{
$this->ipsclass->DB->do_update( 'task_manager', $save, 'task_id='.$task_id );
$this->ipsclass->main_msg = 'Çàäà÷à óñïåøíî èçìåíåíà';
}
else
{
$this->ipsclass->DB->do_insert( 'task_manager', $save );
$this->ipsclass->main_msg = 'Çàäà÷à óñïåøíî ñîõðàíåíà';
}
$this->functions->save_next_run_stamp();
$this->task_show_tasks();
}
/*-------------------------------------------------------------------------*/
// Task Manager: Form
/*-------------------------------------------------------------------------*/
function task_form($type='edit')
{
$this->ipsclass->admin->nav[] = array( '', 'Äîáàâëåíèå/èçìåíåíèå çàäà÷è' );
//-----------------------------------------
// Init Vars
//-----------------------------------------
$form = array();
$task_id = intval( $this->ipsclass->input['task_id'] );
# Drop downs
$dropdows = array();
//-----------------------------------------
// Edit or add?
//-----------------------------------------
if ( $type == 'edit' )
{
$button = "Îòðåäàêòèðîâàòü çàäà÷ó";
$formbit = "task_edit_do";
$this->ipsclass->html_help_title = "";
$this->ipsclass->html_help_msg = "";
$task = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'task_manager', 'where' => "task_id=$task_id" ) );
if ( $task['task_safemode'] and ! IN_DEV )
{
$this->ipsclass->main_msg = "Âû íå ìîæåòå èçìåíèòü ýòó çàäà÷ó.";
$this->task_show_tasks();
return;
}
$title = "Èçìåíåíèå çàäà÷è: ".$group['cb_group_name'];
}
else
{
$button = "Äîáàâèòü ýòó çàäà÷ó";
$formbit = "task_add_do";
$this->ipsclass->html_help_title = "";
$this->ipsclass->html_help_msg = "";
$task = array();
$title = "Äîáàâëåíèå çàäà÷è";
}
//-----------------------------------------
// Create drop downs
//-----------------------------------------
$dropdown['_minute'] = array( 0 => array( '-1', 'Êàæäóþ ìèíóòó' ) );
$dropdown['_hour'] = array( 0 => array( '-1', 'Êàæäûé ÷àñ' ), 1 => array( '0', '0 - Ïîëíî÷ü' ) );
$dropdown['_wday'] = array( 0 => array( '-1', 'Êàæäûé äåíü íåäåëè' ) );
$dropdown['_mday'] = array( 0 => array( '-1', 'Êàæäûé äåíü ìåñÿöà' ) );
for( $i = 0 ; $i < 60; $i++ )
{
$dropdown['_minute'][] = array( $i, $i );
}
for( $i = 1 ; $i < 24; $i++ )
{
if ( $i < 12 )
{
$ampm = $i.' am';
}
else if ( $i == 12 )
{
$ampm = 'Ïîëäåíü';
}
else
{
$ampm = $i - 12 . ' pm';
}
$dropdown['_hour'][] = array( $i, $i. ' - ('.$ampm.')' );
}
for( $i = 1 ; $i < 32; $i++ )
{
$dropdown['_mday'][] = array( $i, $i );
}
$dropdown['_wday'][] = array( '0', 'Âîñêðåñåíüå' );
$dropdown['_wday'][] = array( '1', 'Ïîíåäåëüíèê' );
$dropdown['_wday'][] = array( '2', 'Âòîðíèê' );
$dropdown['_wday'][] = array( '3', 'Ñðåäà' );
$dropdown['_wday'][] = array( '4', '×åòâåðã' );
$dropdown['_wday'][] = array( '5', 'Ïÿòíèöà' );
$dropdown['_wday'][] = array( '6', 'Ñóááîòà' );
//-----------------------------------------
// Form elements
//-----------------------------------------
$form['task_title'] = $this->ipsclass->adskin->form_input( 'task_title' , $_POST['task_title'] ? $_POST['task_title'] : $task['task_title'] );
$form['task_description'] = $this->ipsclass->adskin->form_input( 'task_description', $_POST['task_description'] ? $_POST['task_description'] : $task['task_description'] );
$form['task_file'] = $this->ipsclass->adskin->form_simple_input( 'task_file' , $_POST['task_file'] ? $_POST['task_file'] : $task['task_file'] , '20' );
$form['task_minute'] = $this->ipsclass->adskin->form_dropdown( 'task_minute' , $dropdown['_minute'] , $_POST['task_minute'] ? $_POST['task_minute'] : $task['task_minute'] , 'onchange="updatepreview()"' );
$form['task_hour'] = $this->ipsclass->adskin->form_dropdown( 'task_hour' , $dropdown['_hour'] , $_POST['task_hour'] ? $_POST['task_hour'] : $task['task_hour'] , 'onchange="updatepreview()"' );
$form['task_week_day'] = $this->ipsclass->adskin->form_dropdown( 'task_week_day' , $dropdown['_wday'] , $_POST['task_week_day'] ? $_POST['task_week_day'] : $task['task_week_day'] , 'onchange="updatepreview()"' );
$form['task_month_day'] = $this->ipsclass->adskin->form_dropdown( 'task_month_day' , $dropdown['_mday'] , $_POST['task_month_day'] ? $_POST['task_month_day'] : $task['task_month_day'], 'onchange="updatepreview()"' );
$form['task_log'] = $this->ipsclass->adskin->form_yes_no( 'task_log' , $_POST['task_log'] ? $_POST['task_log'] : $task['task_log'] );
$form['task_enabled'] = $this->ipsclass->adskin->form_yes_no( 'task_enabled' , $_POST['task_enabled'] ? $_POST['task_enabled'] : $task['task_enabled'] );
if ( IN_DEV )
{
$form['task_key'] = $this->ipsclass->adskin->form_input( 'task_key' , $_POST['task_key'] ? $_POST['task_key'] : $task['task_key'] );
$form['task_safemode'] = $this->ipsclass->adskin->form_yes_no( 'task_safemode', $_POST['task_safemode'] ? $_POST['task_safemode'] : $task['task_safemode'] );
}
$this->ipsclass->html .= $this->html->task_manager_form( $form, $button, $formbit, $type, $title, $task );
$this->ipsclass->admin->output();
}
/*-------------------------------------------------------------------------*/
// Task Manager: Overview
/*-------------------------------------------------------------------------*/
function task_show_tasks()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$row = array();
$content = "";
//-----------------------------------------
// List tasks (pointless comment)
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'task_manager', 'order' => 'task_safemode, task_next_run' ) );
$this->ipsclass->DB->simple_exec();
while ( $row = $this->ipsclass->DB->fetch_row() )
{
$row['task_minute'] = $row['task_minute'] != '-1' ? $row['task_minute'] : '-';
$row['task_hour'] = $row['task_hour'] != '-1' ? $row['task_hour'] : '-';
$row['task_month_day'] = $row['task_month_day'] != '-1' ? $row['task_month_day'] : '-';
$row['task_week_day'] = $row['task_week_day'] != '-1' ? $row['task_week_day'] : '-';
if ( time() > $row['task_next_run'] )
{
$row['_image'] = 'task_run_now.gif';
}
else
{
$row['_image'] = 'task_run.gif';
}
$row['_next_run'] = gmdate( 'j M Y - G:i', $row['task_next_run'] );
$row['_class'] = $row['task_enabled'] != 1 ? " style='color:gray'" : '';
$row['_title'] = $row['task_enabled'] != 1 ? " (Îòêëþ÷åíî)" : '';
$row['_next_run'] = $row['task_enabled'] != 1 ? "<span style='color:gray'><s>{$row['_next_run']}</s></span>" : $row['_next_run'];
$content .= $this->html->task_manager_row( $row );
}
//-------------------------------
// Print it
//-------------------------------
$this->ipsclass->html .= $this->html->task_manager_wrapper( $content, gmdate( 'jS F Y - h:i A' ) );
$this->ipsclass->admin->output();
}
}
?>