| [ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 3 /* 4 # ***** BEGIN LICENSE BLOCK ***** 5 # This file is part of Plume CMS, a website management application. 6 # Copyright (C) 2001-2005 Loic d'Anterroches and contributors. 7 # 8 # Plume CMS is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # Plume CMS is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # ***** END LICENSE BLOCK ***** */ 23 24 25 /** 26 * @class checklist 27 * 28 * Class to run series of tests/checks. 29 * A result of a test can be good, bad or warning. 30 */ 31 32 class CheckList 33 { 34 var $tests = array(); 35 36 /** 37 * Create a new checklist with a test. 38 * 39 * @see addtest 40 */ 41 function CheckList($id='', $res=0, $good='', $bad='', $warning='') 42 { 43 $this->addTest($id, $res, $good, $bad, $warning); 44 } 45 46 /** 47 * Add a new test 48 * 49 * @param string id of the test 50 * @param int result of the test (0=bad, 1=good, 2=warning) 51 * @param string String in case of good result 52 * @param sring String in case of bad result 53 * @param string String in case of warning 54 * @return bool valid or invalid test 55 */ 56 function addTest($id='', $res=0, $good='', $bad='', $warning='') 57 { 58 if (empty($id)) { 59 return false; 60 } 61 $string = $good; 62 if (2 === $res) { 63 $string = $warning; 64 } elseif (false === $res or 0 === $res) { 65 $string = $bad; 66 $res = 0; 67 } else { 68 $res = 1; 69 } 70 $this->tests[] = array( 71 'id' => $id, 72 'res' => $res, 73 'mess' => $string 74 ); 75 return true; 76 } 77 78 /** 79 * Compatibility with the dotclear checklist 80 */ 81 function addItem($id='', $res=0, $good='', $bad='') 82 { 83 if (NULL === $res) $res = 1; 84 return $this->addTest($id, $res, $good, $bad); 85 } 86 87 /** 88 * Check the tests, 2 levels all good or good and warnings. 89 * 90 * @param int Level 1=all good, 2=warnings ok (default) 91 * @return bool global result of the tests 92 */ 93 function checkAll($level=2) 94 { 95 foreach ($this->tests as $test) { 96 if (0 === $test['res']) return false; 97 if (1 === $level && 2 === $test['res']) return false; 98 } 99 return true; 100 } 101 102 /** 103 * Get the an html list with the results of the tests. 104 * 105 * @param string Path to the images (no trailing slash) 106 * @param string Good image ('check_on.png') 107 * @param string Bad image ('check_off.png') 108 * @param string Warning image ('check_wait.png') 109 * @return string HTML code 110 */ 111 function getHtml($path, $gi='check_on.png', 112 $bi='check_off.png', $wi='check_wait.png') 113 { 114 reset($this->tests); 115 $o = '<ul class="checklist">'."\n"; 116 foreach ($this->tests as $test) { 117 $img = $path.'/'.$gi; 118 $string = $test['mess']; 119 if (2 === $test['res']) { 120 $img = $path.'/'.$wi; 121 } elseif (false == $test['res']) { 122 $img = $path.'/'.$bi; 123 } 124 $o .= '<li><img src="'.$img.'" /> '.$string.'</li>'."\n"; 125 } 126 $o .= '</ul>'."\n\n"; 127 return $o; 128 } 129 } 130 131 132 133 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
|