06a7bcbcf7ce4d75e45580d08e8e675b45ac3f83
[atutor.git] / docs / mods / _standard / photos / include / classes / AjaxMessage.class.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010                                             */
6 /* Inclusive Design Institute                                          */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
9 /* This program is free software. You can redistribute it and/or           */
10 /* modify it under the terms of the GNU General Public License             */
11 /* as published by the Free Software Foundation.                                           */
12 /***********************************************************************/
13 // $Id$
14 if (!defined('AT_INCLUDE_PATH')) exit;
15
16 /** 
17  * Ajax Message
18  * Returns a plain message without using the savant template.
19  *
20  * @author      Harris Wong
21  * @date        Feb 2, 2010
22  */
23 class AjaxMessage extends Message {
24         /**
25          * Override constructor
26          */
27         function AjaxMessage(){
28         }
29
30         /**
31         * Overrides Message.printAbstract.  Now prings plain message
32         * @access  public
33         * @param   string $type                                 error|warning|info|feedback|help|help_pop
34         * @return  string       Singular message instant
35         * @author  Harris Wong
36         */
37         function printAbstract($type) {
38                 if (!isset($_SESSION['message'][$type])) return;
39
40                 $_result = array();
41                 
42                 foreach($_SESSION['message'][$type] as $e => $item) {
43                         $result = '';
44
45                         // $item is either just a code or an array of argument with a particular code
46                         if (is_array($item)) {                  
47                                 /* this is an array with terms to replace */
48                                 $first = array_shift($item);
49                                 $result = _AT($first); // lets translate the code
50
51                                 if ($result == '') { // if the code is not in the db lets just print out the code for easier trackdown
52                                         $result = '[' . $first . ']';
53                                 }
54                                         
55                                 $terms = $item;
56                         
57                                 /* replace the tokens with the terms */
58                                 $result = vsprintf($result, $terms);
59                                 
60                         } else {
61                                 $result = _AT($item);
62                                 if ($result == '') // if the code is not in the db lets just print out the code for easier trackdown
63                                         $result = '[' . $item . ']';
64                         }
65                         
66                         array_push($_result, $result); // append to array
67                 }
68                 //clean
69                 unset($_SESSION['message'][$type]);
70                 //return
71                 if (count($_result) > 0) {
72                         foreach ($_result as $e){
73                                 $e = preg_replace('/<small>(.*)<\/small>/', '', $e);
74                                 return $e;
75                         }
76                 }
77
78         }
79
80         //override
81         function printErrors($optional=null) {
82                 if ($optional != null)  // shortcut
83                         $this->addAbstract('error', $optional);
84                 return $this->printAbstract('error');
85         }
86 }
87 ?>