function BrowsePhoo
(){
$model =&
$GLOBALS['app']->
LoadGadget('Phoo',
'AdminModel');
$t =&
new JawsTemplate
("gadgets/Phoo/templates/");
$t->
Load ("BrowsePhoo.html");
$t->
SetBlock("phoo");
$albums = $model->GetAlbumsByDate();
if (!JawsError::IsError ($albums)) {
$t->SetBlock ("phoo/photos");
$datecombo =& Piwi::CreateWidget('Combo', 'date');
$datecombo->SetStyle("width: 200px;");
$datecombo->AddOption ("","");
$mindate = $model->GetMinDate();
if ($mindate) {
$maxdate = $model->GetMaxDate();
$mindateArray = explode('/', $mindate);
$maxdateArray = explode('/', $maxdate);
for ($year = $maxdateArray[2]; $year >= $mindateArray[2]; $year--) {
if ($maxdateArray[2] == $mindateArray[2]) {
$mstart = $maxdateArray[0];
$mend = $mindateArray[0];
} else {
if ($year == $maxdateArray[2])
$mstart = $maxdateArray[0];
else
$mstart = 12;
if ($year == $mindateArray[2])
$mend = $mindateArray[0];
else
$mend = 1;
}
for ($m = $mstart; $m >= $mend; $m--) {
$month = $GLOBALS['app']->Date->MonthString ($m);
$datecombo->AddOption ("{$month} {$year}","{$m}/{$year}");
}
}
}
$t->SetVariable("date",_t("GLOBAL_DATE"));
$datecombo->SetDefault (isset($_REQUEST["date"]) ? $_REQUEST["date"] : null);
$datecombo->AddEvent (new JSEvent (ON_CHANGE, "selectAllAlbums(); this.form.submit();"));
$t->SetVariable("date_combo",$datecombo->Get());
$albumcombo =& Piwi::CreateWidget('Combo', 'album[]');
$albumcombo->SetID('albums');
$albumcombo->SetStyle('width: 200px;');
$albumcombo->SetSize(12);
$albumcombo->SetMultiple(true);
foreach ($albums as $a) {
// FIXME: Ugly hack to add title to albumcombo
$o =& Piwi::CreateWidget('ComboOption', $a['id'], $GLOBALS['app']->XSS->filter($a['name']));
$o->SetTitle(_t('PHOO_NUM_PHOTOS_ALBUM', $a['howmany']) . ' / '.
_t('PHOO_ALBUM_CREATION_DATE', $GLOBALS['app']->Date->Format($a['createtime'])));
$albumcombo->_options[$a['id']] = $o;
}
$albumcombo->SetDefault (isset ($_REQUEST["album"]) ? $_REQUEST["album"] : "");
$albumcombo->AddEvent (new JSEvent (ON_CHANGE, "this.form.submit();"));
$t->SetVariable("albums",_t("PHOO_ALBUMS"));
$script = '';
if (empty($_REQUEST["album"])) {
$script .= "";
}
$t->SetVariable("albums_combo",$albumcombo->Get().$script);
// Ugly hack to convert $_REQUEST["album"] to array...
if ((!empty($_REQUEST["album"])) && (!is_array($_REQUEST["album"]))) {
$aux = $_REQUEST["album"];
$_REQUEST["album"] = array();
$_REQUEST["album"][] = $aux;
}
// Show albums
if ((!empty($_REQUEST["album"])) && (is_array($_REQUEST["album"]))) {
foreach ($_REQUEST["album"] as $albumId) {
if (!empty($_REQUEST["date"])) {
$aux = explode("/",$_REQUEST["date"]);
$month = $aux[0];
$year = $aux[1];
} else {
$month = null;
$year = null;
}
$album = $model->GetAlbum($albumId, $month, $year);
if (!JawsError::IsError ($album)) {
if ((isset ($album["images"]) &&
!is_array($album["images"])) &&
(count($album["images"]) == 0) &&
(checkdate ($month, 1, $year))) {
continue;
}
$t->SetBlock ("phoo/photos/albums");
$t->SetVariable ("title", $album["name"]);
$t->SetVariable ("description",$this->ParseText($album["description"]));
$t->SetVariable ("createtime", $GLOBALS['app']->Date->Format($album["createtime"]));
if ((isset ($album["images"]) && is_array($album["images"])) && (count($album["images"]) > 0)) {
// Show photos
foreach ($album["images"] as $img) {
$t->SetBlock ("phoo/photos/albums/item");
$t->SetVariable ("url","admin.php?gadget=Phoo&action=BrowsePhoo&image={$img["id"]}&album={$albumId}");
$t->SetVariable ("image", $img["image"]);
$t->SetVariable ("name",$img["name"]);
$t->SetVariable ("album",$img["albumid"]);
if ($img["published"] == 'N') {
$t->SetVariable ("notpublished", _t("PHOO_NOT_PUBLISHED"));
} else {
$t->SetVariable ("notpublished","");
}
$t->ParseBlock ("phoo/photos/albums/item");
}
}
$t->ParseBlock ("phoo/photos/albums");
} else {
$GLOBALS["session"]->PushLastResponse (_t("PHOO_INEXISTENT_ALBUM"), RESPONSE_ERROR);
}
}
}
//si ya se selecciono una imagen:
if (isset($_GET["image"]) && isset($_GET["album"])){
//desplegar la foto seleccionada y el form de finalizacion.
$image = $model->GetImage($_REQUEST["image"], $_GET["album"]);
if (JawsError::IsError ($image)) {
$GLOBALS["session"]->PushLastResponse ($image->GetMessage(), RESPONSE_ERROR);
JawsHeader::Location ("admin.php?gadget=Phoo&action=Admin");
}
$id = $image["id"];
$filename = $image["original"];
$title = $image["title"];
$desc = $image["description"];
$published = $image["published"];
$t->SetBlock ("phoo/photos/selected");
$t->SetVariable ("t_title",_t("PHOO_PHOTO_TITLE"));
$t->SetVariable ("t_css",_t("PHOO_CSS"));
$t->SetVariable ("t_size",_t("PHOO_SIZE"));
$t->SetVariable ("t_thumb",_t("PHOO_THUMBS"));
$t->SetVariable ("t_medium",_t("PHOO_MEDIUM"));
$t->SetVariable ("s_image", JawsImage::GetThumbPath($filename));
$t->SetVariable ("s_name", $title);
$t->SetVariable ("s_picture",$id);
$t->SetVariable ("s_album",$_GET["album"]);
$t->ParseBlock ("phoo/photos/selected");
}
$t->ParseBlock("phoo/photos");
} else {
$t->SetBlock ("phoo/noalbums");
$t->SetVariable ("message", _t("PHOO_EMPTY_ALBUMSET"));
$t->SetVariable("form",$form->Get());
$t->ParseBlock ("phoo/noalbums");
}
$t->ParseBlock("phoo");
return $t->Get();
}