Exemplo n.º 1
0
 function get_help($type)
 {
     $message = ucwords($type) . " fields:";
     $fields = command::get_fields($type);
     foreach ((array) $fields as $k => $arr) {
         $message .= "\n      " . $k . ":\t" . $arr[1];
     }
     return $message;
 }
Exemplo n.º 2
0
 public function test_process_command()
 {
     $co = new command(array('C', '20', '4'));
     //create a canvas
     $result = $co->process_command();
     $this->assertSame($result, $co->process_command());
     //draw a line
     $result = $co->process_command(array('L', '1', '2', '6', '2'));
     $this->assertSame($result, $co->process_command(array('L', '1', '2', '6', '2')));
     //draw a rectangle
     $result = $co->process_command(array('R', '1', '1', '6', '4'));
     $this->assertSame($result, $co->process_command(array('L', '1', '2', '6', '2')));
 }
Exemplo n.º 3
0
 public static function run()
 {
     // On a besoin du path où mettre le fichier de backup
     $opts = array('path' => 'y', 'sn' => 'y');
     $r = command::get_runner($opts);
     $options = getopt($r->shortoptions, $r->options);
     $error = false;
     if (!isset($options['path']) || !is_dir($options['path'])) {
         logger::shout('loption --path nest pas valide');
         $error = true;
     }
     if (!isset($options['sn'])) {
         logger::shout('indiquer le shortname --sn ');
         $error = true;
     }
     if ($error) {
         return;
     }
     // $permissions = fileperms($options['path']);
     // logger::shout($options['path'] . ' permissions:' . $permissions. PHP_EOL);
     backup::execute($options['sn'], $options['path']);
 }
Exemplo n.º 4
0
 public static function run()
 {
     // On a besoin du path où mettre le fichier de backup
     $opts = array('file' => 'y', 'cat' => 'y');
     $r = command::get_runner($opts);
     $options = getopt($r->shortoptions, $r->options);
     $error = false;
     if (!isset($options['file'])) {
         logger::shout('loption --file doit etre indiquee');
         return;
     }
     if (!file_exists($options['file'])) {
         cli_error("Backup file '" . $options['file'] . "' does not exist.");
         $error = true;
     }
     if (!is_readable($options['file'])) {
         cli_error("Backup file '" . $options['file'] . "' is not readable.");
         $error = true;
     }
     if (!isset($options['cat'])) {
         logger::shout('indiquer la categorie --cat ');
         $error = true;
     }
     global $DB;
     // Check if category is OK.
     if (isset($options['cat'])) {
         $category = $DB->get_record('course_categories', array('id' => $options['cat']), '*', MUST_EXIST);
         if (!isset($category->id)) {
             logger::shout('La categorie ' . $options['cat'] . ' nexiste pas.');
             $error = true;
         }
     }
     if ($error) {
         return;
     }
     // $permissions = fileperms($options['path']);
     // logger::shout($options['path'] . ' permissions:' . $permissions. PHP_EOL);
     restore::execute($options['file'], $options['cat']);
 }
Exemplo n.º 5
0
                case 'B':
                    if (!$this->canvas->get_canvas_state()) {
                        $messages->set_message('line-error-1');
                    } elseif (count($this->command_array) == 4) {
                        $command = $this->command_array;
                        $this->canvas->bucket_fill(array($command[1], $command[2]), $command[3]);
                        $messages->set_message('general-ok-0');
                    } else {
                        $messages->set_message('general-error-0');
                    }
                    break;
                    //Restart the app
                //Restart the app
                case 'Q':
                    $messages->set_message('general-ok-0');
                    $messages->is_reload();
                    break;
                default:
                    break;
            }
        } else {
            return false;
        }
        return $this->canvas->get_canvas_string($messages) . '<br/>' . $messages->get_current_message();
    }
}
if (isset($_GET['command'])) {
    //Initialization of the object with the params given by the ajax call (GET).
    $obj_command = new command(explode(' ', trim(preg_replace('/\\s+/', ' ', $_GET['command']))), $_GET['canvas']);
    echo $obj_command->process_command();
}
Exemplo n.º 6
0
 /**
  * A generic method to edit entities
  * @param string $entity which type of entity to edit
  * @param integer $id the id of the entity
  * @param array $options the edit options see email/lib/command.inc.php for the various options
  * @return array success or failure object
  */
 public function edit_entity($entity, $id, $options = false)
 {
     $options[$entity] = $id;
     if (strtolower($options[$entity]) == "help") {
         return array("status" => "msg", "message" => command::get_help($entity));
     } else {
         if ($options) {
             $command = new command();
             return $command->run_commands($options);
         }
     }
 }
Exemplo n.º 7
0
 function process_one_email($email_receive)
 {
     $current_user =& singleton("current_user");
     $orig_current_user =& $current_user;
     // wrap db queries in a transaction
     $db = new db_alloc();
     $db->start_transaction();
     inbox::change_current_user($email_receive->mail_headers["from"]);
     $current_user =& singleton("current_user");
     $email_receive->save_email();
     // Run any commands that have been embedded in the email
     $command = new command();
     $fields = $command->get_fields();
     $commands = $email_receive->get_commands($fields);
     try {
         $command->run_commands($commands, $email_receive);
     } catch (Exception $e) {
         $current_user =& $orig_current_user;
         singleton("current_user", $current_user);
         $db->query("ROLLBACK");
         $failed = true;
         throw new Exception($e);
     }
     // Commit the db, and move the email into its storage location eg: INBOX.task1234
     if (!$failed && !$TPL["message"]) {
         $db->commit();
         $email_receive->archive();
     }
     // Put current_user back to normal
     $current_user =& $orig_current_user;
     singleton("current_user", $current_user);
 }