gallery.inc.php 4.9 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php
/* Copyright 2006
 * - Julien Etelain < julien at pmad dot net >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

/**
 * @file
 */

/**
29 30 31 32 33 34
 * Permet d'afficher une "galerie" de contents ou d'éléments.
 *
 * Nottament utilisé dans le SAS, le matmatronch...
 *
 * @author Julien Etelain
 * @ingroup display_cts
Ayolo's avatar
Ayolo committed
35 36 37
 */
class gallery extends stdcontents
{
38

Ayolo's avatar
Ayolo committed
39 40 41 42 43
	var $page;
	var $id_name;
	var $actions;
	var $batchactions;
	var $get_page;
44 45


Ayolo's avatar
Ayolo committed
46 47 48 49 50 51 52 53 54 55 56
	/**
	 * Construit une galerie.
	 * API similaire à sqltable.
	 * @param $title Tire du contents
	 * @param $class Classe css complémentaire
	 * @param $name Nom du formulaire
	 * @param $id_name Nom du cham identifiant
	 * @param $actions Actions individuelles sur les éléments (array(action=>titre))
	 * @param $batchactions Actions collectives (array(action=>titre))
	 * @see sqltable
	 */
57
	function gallery($title=false,$class=false,$name=false,$page=false,$id_name=false,$actions=array(),$batchactions=array())
Ayolo's avatar
Ayolo committed
58 59
	{
		$this->title = $title;
60 61


Ayolo's avatar
Ayolo committed
62 63 64 65
		$this->page = $page;
		$this->id_name = $id_name;
		$this->actions = $actions;
		$this->batchactions = $batchactions;
66

Ayolo's avatar
Ayolo committed
67 68 69 70
		if ( strstr($page,"?"))
			$this->get_page = $page."&";
		else
			$this->get_page = $page."?";
71

Ayolo's avatar
Ayolo committed
72 73
		if ( count($batchactions) )
			$this->buffer .= "<form name=\"$name\" action=\"$page\" method=\"POST\">\n";
74

Ayolo's avatar
Ayolo committed
75 76 77 78 79 80 81 82 83 84 85 86
		$this->buffer .= "<div class=\"gallery".($class?" ".$class:"")."\">\n";
	}
	/**
	 * Ajoute un élèment
	 * @param $data Contenu (html brut ou stdcontents)
	 * @param $lable Légende de l'élèment (affiché en bas de la fiche)
	 * @param $id Id de l'élèment (si actions ou batchactions)
	 * @param $actallowed Actions authorisés (false:aucune, true:toutes, array(action1,action2...)
	 * @param $class Classe css complémentaire
	 */
	function add_item ( $data, $label=false, $id=false, $actallowed=false, $class=false )
	{
87

Ayolo's avatar
Ayolo committed
88
		$this->buffer .= "<div class=\"galitem".($class?" ".$class:"")."\">\n";
89

Ayolo's avatar
Ayolo committed
90
		$this->buffer .= "<div class=\"galitemdata\">";
91

Ayolo's avatar
Ayolo committed
92 93 94 95
		if ( is_object($data) )
			$this->buffer .= $data->html_render()."\n";
		else
			$this->buffer .= $data."\n";
96

Ayolo's avatar
Ayolo committed
97
		$this->buffer .= "</div>";
98

Ayolo's avatar
Ayolo committed
99
		$this->buffer .= "<div class=\"galiteminfo\">";
100

Ayolo's avatar
Ayolo committed
101 102
		if ( count($this->batchactions) )
			$this->buffer .= "<input type=\"checkbox\" class=\"chkbox\" name=\"".$this->id_name."s[]\" value=\"".$id."\" />\n";
103

Ayolo's avatar
Ayolo committed
104 105
		if ( $label )
			$this->buffer .= $label."\n";
106

Ayolo's avatar
Ayolo committed
107 108
		if ( $actallowed && $label )
			$this->buffer .= "</div><div class=\"tooldep\">\n";
109

Ayolo's avatar
Ayolo committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
		if ( is_array($actallowed) )
		{
			foreach ( $actallowed as $action  )
				$this->_render_action($id, $action, $this->actions[$action] );
		}
		elseif ( $actallowed==true )
		{
			foreach ( $this->actions as $action => $name )
				$this->_render_action($id, $action, $name);
		}

		$this->buffer .= "</div>\n";

		$this->buffer .= "</div>\n";
	}
125

Ayolo's avatar
Ayolo committed
126 127 128 129 130 131 132 133 134 135
	function _render_action(  $id, $action, $name)
	{
		global $wwwtopdir,$topdir;
		$this->buffer .= "<a href=\"".$this->generate_hlink($action,$id)."\">";
		if ( file_exists( $topdir . "images/actions/" . $action.".png")   )
			$this->buffer .= "<img src=\"".$wwwtopdir . "images/actions/" . $action.".png\" alt=\"".htmlentities($name,ENT_NOQUOTES,"UTF-8")."\" title=\"".htmlentities($name,ENT_NOQUOTES,"UTF-8")."\" class=\"icon\" />";
		else
			$this->buffer .= htmlentities($name,ENT_NOQUOTES,"UTF-8");
		$this->buffer .= "</a>\n";
	}
136

Ayolo's avatar
Ayolo committed
137 138 139 140 141 142 143 144 145
	function generate_hlink ( $action, $id )
	{
		if ( strpos($id,"=") )
		{
			if ( !$action )
				return htmlentities($this->get_page.$id);
			else
				return htmlentities($this->get_page.$id."&action=".$action);
		}
146

Ayolo's avatar
Ayolo committed
147 148 149 150 151
		if ( !$action )
			return htmlentities($this->get_page.$this->id_name."=".$id);
		else
			return htmlentities($this->get_page.$this->id_name."=".$id."&action=".$action);
	}
152

Ayolo's avatar
Ayolo committed
153 154 155
	function html_render ()
	{
		$this->buffer .= "<div class=\"clearboth\"></div>\n</div>";
156

Ayolo's avatar
Ayolo committed
157 158 159 160 161 162 163
		if ( count($this->batchactions) )
		{
			$this->buffer .= "<p>\n<select name=\"action\">\n";
			foreach ($this->batchactions as $action => $name )
				$this->buffer .= "<option value=\"$action\">".htmlentities($name,ENT_NOQUOTES,"UTF-8")."</option>\n";
			$this->buffer .= "</select>\n<input type=\"submit\" value=\"ok\" />\n</p>\n";
			$this->buffer .= "</form>\n";
164
		}
Ayolo's avatar
Ayolo committed
165

166
		return $this->buffer;
Ayolo's avatar
Ayolo committed
167
	}
168

Ayolo's avatar
Ayolo committed
169 170 171
}

?>