AlternC/bureau/class/m_action.php

154 lines
4.3 KiB
PHP
Raw Normal View History

2013-04-19 12:24:00 +00:00
<?php
/*
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Original Author of file: Lerider Steven
Purpose of file: Manage generic actions.
----------------------------------------------------------------------
*/
/**
*
* @copyright AlternC-Team 2002-2013 http://alternc.org/
*/
class m_action {
/*---------------------------------------------------------------------------*/
/** Constructor
*/
function m_action() {
}
/*
* function to set the cration of a file
*/
2013-04-22 08:23:28 +00:00
function create_file($file,$content="",$user="root") {
2013-04-19 15:23:26 +00:00
return $this->set('create_file',$user, array('file'=>$file,'content'=>$content));
2013-04-19 12:24:00 +00:00
}
/*
* function to set the cration of a file
*/
function create_dir($dir,$user="root") {
2013-04-19 15:23:26 +00:00
return $this->set('create_dir',$user, array('dir'=>$dir));
2013-04-19 12:24:00 +00:00
}
/*
* function to delete file / folder
*/
function del($dir) {
2013-04-19 15:23:26 +00:00
return $this->set('delete',$user, array('dir'=>$dir));
2013-04-19 12:24:00 +00:00
}
/*
* function returning the first not locked line of the action table
*/
2013-04-22 08:23:28 +00:00
function move($src,$dst,$user="root") {
2013-04-19 15:23:26 +00:00
return $this->set('move',$user, array('src'=>$src, 'dst'=>$dst));
2013-04-19 12:24:00 +00:00
}
/*
* function archiving a directory ( upon account deletion )
*/
2013-04-22 08:23:28 +00:00
function archive($archive,$dir) {
global $cuid,$db;
$db->query("select login from membres where uid=$cuid;");
$db->next_record();
if (!$db->Record["login"]) {
$err->raise("action",_("Login corresponding to $cuid not found"));
return false;
}
$uidlogin=$cuid."-".$db->Record["login"];
$BACKUP_DIR="/tmp/backup/";
2013-04-19 15:23:26 +00:00
//utiliser la function move après avoir construit le chemin
$today=getdate();
$dest=$BACKUP_DIR.'/'.$today["year"].'-'.$today["mon"].'/'.$uidlogin.'/'.$dir;
2013-04-19 15:23:26 +00:00
$this->move($archive,$dest);
2013-04-19 12:24:00 +00:00
}
/*
*function inserting the action in the sql table
*/
2013-04-19 15:23:26 +00:00
function set($type,$user,$parameters) {
2013-04-19 12:24:00 +00:00
global $db;
2013-04-19 14:19:50 +00:00
2013-04-19 15:23:26 +00:00
$serialized=serialize($parameters);
2013-04-19 14:19:50 +00:00
switch($type){
case 'create_file':
//do some shit
2013-04-22 12:31:43 +00:00
$query="insert into actions values ('','CREATE_FILE','$serialized','','','','$user','');";
2013-04-22 08:23:28 +00:00
break;
2013-04-19 14:19:50 +00:00
case 'create_dir':
//do more shit
2013-04-22 12:31:43 +00:00
$query="insert into actions values ('','CREATE_DIR','$serialized','','','','$user','');";
2013-04-22 08:23:28 +00:00
break;
2013-04-19 14:19:50 +00:00
case 'move':
//do more shit
2013-04-22 12:31:43 +00:00
$query="insert into actions values ('','MOVE','$serialized','','','','$user','');";
2013-04-22 08:23:28 +00:00
break;
2013-04-19 14:19:50 +00:00
case 'delete':
//do more shit
2013-04-22 12:31:43 +00:00
$query="insert into actions values ('','DELETE','$serialized','','','','$user','');";
2013-04-22 08:23:28 +00:00
break;
2013-04-19 14:19:50 +00:00
case 'archive':
//do more shit
2013-04-22 12:31:43 +00:00
$query="insert into actions values ('','ARCHIVE','$serialized','','','','$user','');";
2013-04-22 08:23:28 +00:00
break;
2013-04-19 14:19:50 +00:00
default:
return false;
}
2013-04-22 12:31:43 +00:00
if(!$db->query($query))
return false;
return true
2013-04-19 12:24:00 +00:00
}
2013-04-19 14:19:50 +00:00
2013-04-19 12:24:00 +00:00
/*
* function returning the first not locked line of the action table
*/
function get_action() {
global $db;
2013-04-19 15:23:26 +00:00
$tab=array();
2013-04-22 12:31:43 +00:00
$db->query('select * from actions where end is null and begin is null order by id limit 1;');
2013-04-19 14:19:50 +00:00
if ($db->next_record()){
$tab[]=$db->Record;
return $tab;
}else
return false;
2013-04-19 12:24:00 +00:00
}
/*
* function locking an entry while it is being executed by the action script
*/
function begin($id) {
global $db;
2013-04-22 12:31:43 +00:00
$db->query("update actions set begin=now() where id=$id ");
2013-04-19 12:24:00 +00:00
return true;
}
/*
* function locking an entry while it is being executed by the action script
*/
2013-04-22 12:31:43 +00:00
function finish($id,$return=0) {
2013-04-19 12:24:00 +00:00
global $db;
2013-04-22 12:31:43 +00:00
$return=intval($return);
$db->query("update actions set end=now(),status=$return where id=$id");
2013-04-19 12:24:00 +00:00
return true;
}
/*
* function locking an entry while it is being executed by the action script
*/
function cancel($id) {
global $db;
2013-04-22 12:31:43 +00:00
$this->finish($id, 666);
2013-04-19 12:24:00 +00:00
return true;
}
} /* Class action */
?>