sintonia/livesupport/modules/htmlUI/var/ui_scratchPad.class.php

124 lines
3.7 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class uiScratchPad
{
function uiScratchPad(&$uiBase)
{
$this->Base = &$uiBase;
$this->items = &$_SESSION[UI_SCRATCHPAD_SESSNAME]['content'];
$this->order = &$_SESSION[UI_SCRATCHPAD_SESSNAME]['order'];
$this->reloadUrl = UI_BROWSER.'?popup[]=_reload_parent&popup[]=_close';
}
function setReload()
{
$this->Base->redirUrl = $this->reloadUrl;
}
function &get()
{
if (!is_array($this->items))
$this->_load();
return $this->items;
}
function _load()
{
$this->items = array();
$spData = $this->Base->gb->loadPref($this->Base->sessid, UI_SCRATCHPAD_KEY);
if (!PEAR::isError($spData)) {
## ScratchPad found in DB
$arr = explode(' ', $spData);
/*
## Akos old format #####################################
foreach($arr as $val) {
if (preg_match(UI_SCRATCHPAD_REGEX, $val)) {
list ($gunid, $date) = explode(':', $val);
if ($this->Base->gb->_idFromGunid($gunid) != FALSE) {
$res[] = array_merge($this->Base->_getMetaInfo($this->Base->gb->_idFromGunid($gunid)), array('added' => $date));
}
}
}
*/
## new format ##########################################
foreach($arr as $gunid) {
if (preg_match('/[0-9]{1,20}/', $gunid)) {
if ($this->Base->gb->_idFromGunid($this->Base->_toHex($gunid)) != FALSE) {
$this->items[] = $this->Base->_getMetaInfo($this->Base->gb->_idFromGunid($this->Base->_toHex($gunid)));
}
}
}
}
}
function save()
{
foreach($this->items as $val) {
#$str .= $val['gunid'].':'.$val['added'].' '; ## new format ###
$str .= $this->Base->_toInt8($val['gunid']).' '; ## Akos´ old format ###
}
$this->Base->gb->savePref($this->Base->sessid, UI_SCRATCHPAD_KEY, $str);
}
function addItem($id)
{
$item = $this->Base->_getMetaInfo($id);
$sp = $this->get();
foreach ($sp as $key=>$val) {
if ($val['gunid'] == $item['gunid']) {
unset($sp[$key]);
$this->Base->_retMsg('Entry $1 was already on SP since $2.\nMoved to Top.', $item['title'], $val['added']);
} else {
#$this->Base->incAccessCounter($id);
}
}
$sp = array_merge(array($item), is_array($sp) ? $sp : NULL);
for ($n=0; $n<$this->Base->systemPrefs[UI_SCRATCHPAD_MAXLENGTH_KEY]; $n++) {
if (is_array($sp[$n])) $this->items[$n] = $sp[$n];
}
}
function removeItems($ids)
{
if (!$ids)
return; ## empty parameter
if (!is_array($ids))
$ids = array($ids); ## just single id given
foreach ($ids as $id) {
$info = $this->Base->_getMetaInfo($id);
$sp =& $this->get();
foreach ($sp as $key=>$val) {
if ($val['gunid'] == $info['gunid']) {
unset ($sp[$key]);
#$this->Base->decAccessCounter($id);
}
}
}
}
function reOrder($by)
{
foreach ($this->items as $key=>$val) {
$s[$key] = $val[$by];
}
$curr = $this->order[$by];
$this->order = array();
(is_null($curr) || $curr=='arsort') ? $this->order[$by] = 'asort' : $this->order[$by] = 'arsort';
$this->order[$by]($s);
foreach ($s as $key=>$val) {
$res[] = $this->items[$key];
}
$this->items = $res;
}
}
?>