コード例 #1
0
ファイル: Ajax.php プロジェクト: projectesIF/Sirius
    public function deleteDocument($args) {
        $documentId = $this->request->getPost()->get('documentId', '');
        if (!$documentId) {
            throw new Zikula_Exception_Fatal($this->__('no document id'));
        }

        // get document
        $document = ModUtil::apiFunc($this->name, 'user', 'getDocument', array('documentId' => $documentId));
        if (!$document) {
            throw new Zikula_Exception_Fatal($this->__('Document not found.'));
        }

        // the documents only can be deleted by people with EDIT_ACCESS to the module or by creators during the time defined in the module configuration
        if (!SecurityUtil::checkPermission('IWdocmanager::', "$document[categoryId]::", ACCESS_DELETE) && ($document['validated'] == 1 || UserUtil::getVar('uid') != $document['cr_uid'] || DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('deleteTime') * 30 < time())) {
            throw new Zikula_Exception_Fatal($this->__('Sorry! No authorization to access this module.'));
        }

        $deleted = ModUtil::apiFunc($this->name, 'user', 'deleteDocument', array('documentId' => $documentId));
        if (!$deleted) {
            throw new Zikula_Exception_Fatal($this->__('Error! Delete document failed.'));
        }

        if ($document['fileName'] != '') {
            // download the document
            $documentPath = ModUtil::getVar('IWmain', 'documentRoot') . '/' . $this->getVar('documentsFolder') . '/' . $document['fileName'];
            // delete file form server
            if (file_exists($documentPath)) {
                unlink($documentPath);
            }
        }

        // upload the number of documents in category
        ModUtil::apiFunc($this->name, 'user', 'countDocuments', array('categoryId' => $document['categoryId']));

        $content = ModUtil::func($this->name, 'user', 'getDocumentsContent', array('categoryId' => $document['categoryId']));

        return new Zikula_Response_Ajax(array('content' => $content,
                ));
    }
コード例 #2
0
ファイル: User.php プロジェクト: projectesIF/Sirius
    public function deleteDocument($args) {
        // get document
        $document = ModUtil::apiFunc($this->name, 'user', 'getDocument', array('documentId' => $args['documentId']));
        if (!$document) {
            return LogUtil::registerError($this->__('Document not found.'));
        }

        // the documents only can be deleted by people with DELETE_ACCESS to the module or by creators during the time defined in the module configuration
        if (!SecurityUtil::checkPermission('IWdocmanager::', "$document[categoryId]::", ACCESS_DELETE) && ($document['validated'] == 1 || UserUtil::getVar('uid') != $document['cr_uid'] || DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('deleteTime') * 30 < time())) {
            return LogUtil::registerPermissionError();
        }

        if (!DBUtil::deleteObjectByID('IWdocmanager', $args['documentId'], 'documentId')) {
            return LogUtil::registerError($this->__('Error! Update attempt failed.'));
        }
        return true;
    }
コード例 #3
0
ファイル: Admin.php プロジェクト: projectesIF/Sirius
    public function viewStats($args) {
        $statsSaved = unserialize(SessionUtil::getVar('statsSaved'));

        $moduleName = (isset($statsSaved['moduleName'])) ? $statsSaved['moduleName'] : '';
        $fromDate = (isset($statsSaved['fromDate'])) ? $statsSaved['fromDate'] : null;
        $toDate = (isset($statsSaved['toDate'])) ? $statsSaved['toDate'] : '';

        $moduleName = FormUtil::getPassedValue('moduleName', isset($args['moduleName']) ? $args['moduleName'] : $moduleName, 'GETPOST');
        $uname = FormUtil::getPassedValue('uname', isset($args['uname']) ? $args['uname'] : $statsSaved['uname'], 'GETPOST');
        $fromDate = FormUtil::getPassedValue('fromDate', isset($args['fromDate']) ? $args['fromDate'] : $fromDate, 'GETPOST');
        $toDate = FormUtil::getPassedValue('toDate', isset($args['toDate']) ? $args['toDate'] : $toDate, 'GETPOST');
        $uid = FormUtil::getPassedValue('uid', isset($args['uid']) ? $args['uid'] : 0, 'GETPOST');

        if ($uid > 0) {
            $uname = UserUtil::getVar('uname', $uid);
        }

        SessionUtil::setVar('statsSaved', serialize(array('uname' => $uname,
                    'moduleName' => $moduleName,
                    'fromDate' => $fromDate,
                    'toDate' => $toDate,
                )));


        if (!SecurityUtil::checkPermission('IWstats::', '::', ACCESS_ADMIN)) {
            throw new Zikula_Exception_Forbidden();
        }

        $uid = 0;
        $rpp = 50;
        $lastDays = 10;
        $nusers = 0;

        if ($uname != null && $uname != '') {
            // get user id from uname
            $uid = UserUtil::getIdFromName($uname);
            if (!$uid) {
                LogUtil::registerError(__f('User \'%s\' not found', array($uname)));
                $uname = '';
            }
        }

        $time = time();

        if ($fromDate != null) {
            $fromDate = mktime(0, 0, 0, substr($fromDate, 3, 2), substr($fromDate, 0, 2), substr($fromDate, 6, 4));
            $fromDate = date('Y-m-d 00:00:00', $fromDate);
            $fromDate = DateUtil::makeTimestamp($fromDate);
            $fromDate = date('d-m-Y', $fromDate);
        } else {
            $fromDate = date('d-m-Y', $time - $lastDays * 24 * 60 * 60);
        }

        if ($toDate != null) {
            $toDate = mktime(0, 0, 0, substr($toDate, 3, 2), substr($toDate, 0, 2), substr($toDate, 6, 4));
            $toDate = date('Y-m-d 00:00:00', $toDate);
            $toDate = DateUtil::makeTimestamp($toDate);
            $toDate = date('d-m-Y', $toDate);
        } else {
            $toDate = date('d-m-Y', $time);
        }

        // get last records
        $records = ModUtil::apiFunc('IWstats', 'user', 'getAllSummary', array('rpp' => -1,
                    'init' => -1,
                    'fromDate' => $fromDate,
                    'toDate' => $toDate,
                ));

        // get all modules
        $modules = ModUtil::apiFunc('Extensions', 'admin', 'listmodules', array('state' => 0));

        foreach ($modules as $module) {
            $modulesNames[$module['id']] = $module['name'];
            $modulesArray[] = array('id' => $module['id'],
                'name' => $module['name']);
        }

        $modulesNames[0] = $this->__('unknown');

        $usersListArray = array();
        $moduleStatsArray = array();
        $userModulesArray = array();
        $userArray = array();
        $moduleArray = array();
        $usersForModule = array();
        $users = array();
        $usersIpCounter = 0;
        $nRecords = 0;
        $userNRecords = 0;
        $usersList = '';
        $userName = '';
        foreach ($records as $record) {
            $nRecords = $nRecords + $record['nrecords'];
            $usersIpCounter = $usersIpCounter + $record['nips'];
            $users = explode('$$', substr($record['users'], 1, -1)); // substr to remove $ in the begining and the end of the string
            foreach ($users as $user) {
                $oneUser = explode('|', $user);

                if (!in_array($oneUser[0], $usersListArray)) {
                    $nusers++;
                    $usersListArray[] = $oneUser[0];
                }
                if ($oneUser[0] == $uid && $uid > 0) {
                    $userInit = '$' . $uid . '|';
                    $userDataPos = strpos($record['users'], $userInit);
                    $subDataPre = substr($record['users'], $userDataPos + strlen($userInit));
                    $userDataPos = strpos($subDataPre, '$');
                    $subDataPre = substr($subDataPre, 0, $userDataPos);
                    $userModules = explode('#', $subDataPre);
                    foreach ($userModules as $module) {
                        $oneModule = explode('=', $module);
                        if (array_key_exists($modulesNames[$oneModule[0]], $userModulesArray)) {
                            $userModulesArray[$modulesNames[$oneModule[0]]] = $oneModule[1];
                        } else {
                            $userModulesArray[$modulesNames[$oneModule[0]]] = $userModulesArray[$modulesNames[$oneModule[0]]] + $oneModule[1];
                        }

                        $userNRecords = $userNRecords + $oneModule[1];
                    }
                }
                if ($moduleName != '') {
                    $moduleId = ModUtil::getIdFromName($moduleName);
                    if ((strpos($oneUser[1], $moduleId . '=') !== false && strpos($oneUser[1], $moduleId . '=') == 0) || strpos($oneUser[1], '#' . $moduleId . '=') !== false) {
                        // get the number of views
                        $pos = strpos($oneUser[1], $moduleId . '=');
                        if ($pos != 0) {
                            $pos = strpos($oneUser[1], '#' . $moduleId . '=');
                        }
                        $preString = substr($oneUser[1], $pos);
                        //print $preString . '<br />';
                        if ($pos != 0) {
                            $preString = substr($preString, 1);
                        }
                        $pos = strpos($preString, '#');
                        $preString = ($pos == 0) ? $preString : substr($preString, 0, $pos);
                        $num = explode('=', $preString);
                        if (!array_key_exists($oneUser[0], $usersForModule)) {
                            $usersForModule[$oneUser[0]] = $num[1];
                            $usersList .= $oneUser[0] . '$$';
                        } else {
                            $usersForModule[$oneUser[0]] = $usersForModule[$oneUser[0]] + $num[1];
                        }
                    }
                }
            }

            $modules = explode('$$', substr($record['modules'], 1, -1)); // substr to remove $ in the begining and the end of the string
            foreach ($modules as $module) {
                $oneModule = explode('|', $module);
                if (isset($modulesNames[$oneModule[0]])) {
                    if (!array_key_exists($modulesNames[$oneModule[0]], $moduleStatsArray)) {
                        $moduleStatsArray[$modulesNames[$oneModule[0]]] = $oneModule[1];
                    } else {
                        $moduleStatsArray[$modulesNames[$oneModule[0]]] = $moduleStatsArray[$modulesNames[$oneModule[0]]] + $oneModule[1];
                    }
                }
            }
        }

        ksort($userModulesArray);

        if ($uid > 0) {
            $userArray = array('nRecords' => $userNRecords,
                'userModulesArray' => $userModulesArray,
            );
        }

        ksort($moduleStatsArray);

        if ($uid > 0) {
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            $userName = ModUtil::func('IWmain', 'user', 'getUserInfo', array('info' => 'ncc',
                        'sv' => $sv,
                        'uid' => $uid));
        }

        if ($moduleName != '') {
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            $users = ModUtil::func('IWmain', 'user', 'getAllUsersInfo', array('info' => 'ncc',
                        'sv' => $sv,
                        'list' => $usersList,
                    ));
            $users[0] = $this->__('Unregistered');
        }

        return $this->view->assign('users', $users)
                        ->assign('nRecords', $nRecords)
                        ->assign('nusers', $nusers)
                        ->assign('userName', $userName)
                        ->assign('usersIpCounter', $usersIpCounter)
                        ->assign('modulesNames', $modulesNames)
                        ->assign('modulesArray', $modulesArray)
                        ->assign('moduleName', $moduleName)
                        ->assign('uname', $uname)
                        ->assign('fromDate', $fromDate)
                        ->assign('toDate', $toDate)
                        ->assign('userArray', $userArray)
                        ->assign('maxDate', date('Ymd', time()))
                        ->assign('usersForModule', $usersForModule)
                        ->assign('moduleStatsArray', $moduleStatsArray)
                        ->fetch('IWstats_admin_stats.htm');
    }
コード例 #4
0
ファイル: User.php プロジェクト: projectesIF/Sirius
    public function viewDocumentVersions($args) {
        $documentId = FormUtil::getPassedValue('documentId', isset($args['documentId']) ? $args['documentId'] : 0, 'GET');

        // get document
        $documentOrigin = ModUtil::apiFunc($this->name, 'user', 'getDocument', array('documentId' => $documentId));
        if (!$documentOrigin) {
            LogUtil::registerError($this->__('Document not found.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs'));
        }

        $documentOrigin['extension'] = FileUtil::getExtension($documentOrigin['fileName']);
        $documentOrigin['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $documentOrigin['filesize']));

        $categoryId = $documentOrigin['categoryId'];

        // check if user can access to this category
        $canAccess = ModUtil::func($this->name, 'user', 'canAccessCategory', array('categoryId' => $categoryId,
                    'accessType' => 'read',
                ));

        if (!$canAccess) {
            LogUtil::registerError($this->__('You can not access to this document.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs'));
        }

        // versions
        $documents = ModUtil::apiFunc($this->name, 'user', 'getDocumentVersions', array('documentId' => $documentId));

        if (!$documents) {
            LogUtil::registerError($this->__('This document have not versions.'));
            return System::redirect(ModUtil::url($this->name, 'user', 'viewDocs', array('categoryId' => $categoryId)));
        }

        $usersList = $documentOrigin['cr_uid'] . '$$';
        $users = array();
        $canEdit = false;
        $canDelete = false;
        $canAdd = false;

        $canEditCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_EDIT)) ? true : false;
        $canDeleteCategory = (SecurityUtil::checkPermission('IWdocmanager::', "$categoryId::", ACCESS_DELETE)) ? true : false;

        foreach ($documents as $document) {
            $extensionIcon['icon'] = '';
            if ($document['fileName'] != '') {
                $extension = FileUtil::getExtension($document['fileName']);
                $extensionIcon = ($extension != '') ? ModUtil::func('IWmain', 'user', 'getMimetype', array('extension' => $extension)) : '';
            }
            $documents[$document['documentId']]['extension'] = $extensionIcon['icon'];
            if ($document['authorName'] == '') {
                $usersList .= $document['cr_uid'] . '$$';
            }
            $documents[$document['documentId']]['canEdit'] = false;
            $documents[$document['documentId']]['canDelete'] = false;
            if ($canEditCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('editTime') * 30 > time())) {
                $documents[$document['documentId']]['canEdit'] = true;
                $canEdit = true; // in order to show edit icon in legend
            }

            if ($canDeleteCategory || ($document['validated'] == 0 && UserUtil::getVar('uid') == $document['cr_uid'] && DateUtil::makeTimestamp($document['cr_date']) + $this->getVar('deleteTime') * 30 > time())) {
                $documents[$document['documentId']]['canDelete'] = true;
                $canDelete = true; // in order to show delete icon in legend
            }

            $documents[$document['documentId']]['filesize'] = ModUtil::func($this->name, 'user', 'getReadableFileSize', array('filesize' => $document['filesize']));
        }

        if ($usersList != '') {
            // get all users information
            $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
            $users = ModUtil::func('IWmain', 'user', 'getAllUsersInfo', array('sv' => $sv,
                        'info' => 'ncc',
                        'list' => $usersList));
        }

        return $this->view->assign('documentOrigin', $documentOrigin)
                        ->assign('documents', $documents)
                        ->assign('canAdd', $canAdd)
                        ->assign('users', $users)
                        ->assign('canEdit', $canEdit)
                        ->assign('canDelete', $canDelete)
                        ->assign('versionsVision', 1)
                        ->fetch('IWdocmanager_user_viewDocumentVersions.tpl');
    }
コード例 #5
0
/**
 * Smarty function to display an editable dynamic user data field.
 *
 * Example
 * {duditemmodify propattribute='avatar'}
 *
 * Example
 * {duditemmodify propattribute='realname' uid=$uid}
 *
 * Example
 * {duditemmodify item=$item}
 *
 * Parameters passed in via the $params array:
 * -------------------------------------------
 * string item          The Profile DUD item.
 * string uid           User ID to display the field value for (-1 = do not load).
 * string class         CSS class to assign to the table row/form row div (optional).
 * string proplabel     Property label to display (optional overrides the preformated dud item $item).
 * string propattribute Property attribute to display.
 * string error         Property error message.
 * 
 * @param array  $params  All attributes passed to this function from the template.
 * @param object &$smarty Reference to the Zikula_View/Smarty object.
 * 
 * @return string|boolean The results of the module function; empty string if the Profile module is not available; false if error.
 */
function smarty_function_duditemmodify($params, &$smarty)
{
    extract($params);
    unset($params);

    if (!ModUtil::available('Profile')) {
        return '';
    }

    if (!isset($item)) {
        if (isset($proplabel)) {
            $item = ModUtil::apiFunc('Profile', 'user', 'get', array('proplabel' => $proplabel));
        } else if (isset($propattribute)) {
            $item = ModUtil::apiFunc('Profile', 'user', 'get', array('propattribute' => $propattribute));
        } else {
            return false;
        }
    }
    if (!isset($item) || empty ($item)) {
        return false;
    }

    // detect if we are in the registration form
    $onregistrationform = false;
    
    // TODO - will these globals always be available? Is there a utility method out there somewhere to get these?
    global $module, $func;
    
    if (strtolower($module) == 'users' && strtolower($func) == 'register') {
        $onregistrationform = true;
    }

    // skip the field if not configured to be on the registration form 
    if ($onregistrationform && !$item['prop_required']) {
        $dudregshow = ModUtil::getVar('Profile', 'dudregshow', array());
        if (!in_array($item['prop_id'], $dudregshow)) {
            return '';
        }
    }

    $dom = ZLanguage::getModuleDomain('Profile');

    if (!isset($uid)) {
        $uid = UserUtil::getVar('uid');
    }
    if (!isset($class) || !is_string($class)) {
        $class = '';
    }

    if (isset($item['temp_propdata'])) {
        $uservalue = $item['temp_propdata'];
    } elseif ($uid >= 0) {
        // TODO - This is a bit of a hack for admin editing. Need to know if it is a reg.
        $user = UserUtil::getVars($uid);
        $isRegistration = UserUtil::isRegistration($uid);
        $uservalue = UserUtil::getVar($item['prop_attribute_name'], $uid, false, $isRegistration); // ($alias, $uid);
    }

    // try to get the DUD output if it's Third Party
    if ($item['prop_dtype'] != 1) {
        $output = ModUtil::apiFunc($item['prop_modname'], 'dud', 'edit',
                               array('item'      => $item,
                                     'uservalue' => $uservalue,
                                     'class'     => $class));
        if ($output) {
            return $output;
        }
    }

    $render = $smarty;//Zikula_View::getInstance('Profile', false, null, true);

    // assign the default values for the control
    $render->assign('class',         $class);
    $render->assign('value',         DataUtil::formatForDisplay($uservalue));
    
    $render->assign('attributename', $item['prop_attribute_name']);
    $render->assign('proplabeltext', $item['prop_label']);
    $render->assign('note',          $item['prop_note']);
    $render->assign('required',      (bool)$item['prop_required']);
    $render->assign('error',         isset($error) ? $error : '');

    // Excluding Timezone of the generics
    if ($item['prop_attribute_name'] == 'tzoffset') {
        if (empty($uservalue)) {
            $uservalue = UserUtil::getVar('tzoffset') ? UserUtil::getVar('tzoffset') : System::getVar('timezone_offset');
        }

        $tzinfo = DateUtil::getTimezones();

        $render->assign('value',          isset($tzinfo["$uservalue"]) ? "$uservalue" : null);
        $render->assign('selectmultiple', '');
        $render->assign('listoptions',    array_keys($tzinfo));
        $render->assign('listoutput',     array_values($tzinfo));
        return $render->fetch('profile_dudedit_select.tpl');
    }

    if ($item['prop_attribute_name'] == 'avatar') {
        // detect if it's the registration form to skip this
        if ($onregistrationform) {
            return '';
        }

        // only shows a link to the Avatar module if available
        if (ModUtil::available('Avatar')) {
            // TODO Add a change-link to the admins
            // only shows the link for the own user
            if (UserUtil::getVar('uid') != $uid) {
                return '';
            }
            $render->assign('linktext', __('Go to the Avatar manager', $dom));
            $render->assign('linkurl', ModUtil::url('Avatar', 'user', 'main'));
            $output = $render->fetch('profile_dudedit_link.tpl');
            // add a hidden input if this is required
            if ($item['prop_required']) {
                $output .= $render->fetch('profile_dudedit_hidden.tpl');
            }
           
            return $output;
        }

        // display the avatar selector
        if (empty($uservalue)) {
            $uservalue = 'gravatar.gif';
        }
        $render->assign('value', DataUtil::formatForDisplay($uservalue));
        $avatarPath = ModUtil::getVar(Users_Constant::MODNAME, Users_Constant::MODVAR_AVATAR_IMAGE_PATH, Users_Constant::DEFAULT_AVATAR_IMAGE_PATH);
        $filelist = FileUtil::getFiles($avatarPath, false, true, array('gif', 'jpg', 'png'), 'f');
        asort($filelist);

        $listoutput = $listoptions = $filelist;

        // strip the extension of the output list
        foreach ($listoutput as $k => $output) {
            $listoutput[$k] = $output;//substr($output, 0, strrpos($output, '.'));
        }

        $selectedvalue = $uservalue;
//        if (in_array($uservalue, $filelist)) {
//            $selectedvalue = $uservalue;
//        }

        $render->assign('value',          $selectedvalue);
        $render->assign('selectmultiple', '');
        $render->assign('listoptions',    $listoptions);
        $render->assign('listoutput',     $listoutput);
        return $render->fetch('profile_dudedit_select.tpl');
    }

    switch ($item['prop_displaytype'])
    {
        case 0: // TEXT
            $type = 'text';
            break;

        case 1: // TEXTAREA
            $type = 'textarea';
            break;

        case 2: // CHECKBOX
            $type = 'checkbox';

            $editlabel = array_splice(explode('@@', $item['prop_listoptions']), 0, 1);
            if (!empty($editlabel[0])) {
                $render->assign('proplabeltext', __($editlabel[0], $dom));
            }
            break;

        case 3: // RADIO
            $type = 'radio';

            $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item));

            $render->assign('listoptions', array_keys($options));
            $render->assign('listoutput', array_values($options));
            break;

        case 4: // SELECT
            $type = 'select';
            if (DataUtil::is_serialized($uservalue)) {
                $render->assign('value', unserialize($uservalue));
            }

            // multiple flag is the first field
            $options = explode('@@', $item['prop_listoptions'], 2);
            $selectmultiple = $options[0] ? ' multiple="multiple"' : '';
            $render->assign('selectmultiple', $selectmultiple);

            $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item));

            $render->assign('listoptions', array_keys($options));
            $render->assign('listoutput', array_values($options));
            break;

        case 5: // DATE
            $type = 'date';

            // gets the format to use
            $format = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item));
            
            switch (trim(strtolower($format)))
            {
                case 'datelong':
                    //! This is from the core domain (datelong)
                    $format = __('%A, %B %d, %Y');
                    break;
                case 'datebrief':
                    //! This is from the core domain (datebrief)
                    $format = __('%b %d, %Y');
                    break;
                case 'datestring':
                    //! This is from the core domain (datestring)
                    $format = __('%A, %B %d @ %H:%M:%S');
                    break;
                case 'datestring2':
                    //! This is from the core domain (datestring2)
                    $format = __('%A, %B %d');
                    break;
                case 'datetimebrief':
                    //! This is from the core domain (datetimebrief)
                    $format = __('%b %d, %Y - %I:%M %p');
                    break;
                case 'datetimelong':
                    //! This is from the core domain (datetimelong)
                    $format = __('%A, %B %d, %Y - %I:%M %p');
                    break;
                case 'timebrief':
                    //! This is from the core domain (timebrief)
                    $format = __('%I:%M %p');
                    break;
                case 'timelong':
                    //! This is from the core domain (timelong)
                    $format = __('%T %p');
                    break;
            }
            //! This is from the core domain (datebrief)
            $format = !empty($format) ? $format : __('%b %d, %Y');

            // process the temporal data if any
            $timestamp = null;
            if (isset($item['temp_propdata'])) {
                $timestamp = DateUtil::parseUIDate($item['temp_propdata']);
                $uservalue = DateUtil::transformInternalDate($timestamp);
            } elseif (!empty($uservalue)) {
                $timestamp = DateUtil::makeTimestamp($uservalue);
            }

            $render->assign('value',     $uservalue);
            $render->assign('timestamp', $timestamp);
            $render->assign('dudformat', $format);
            break;

        case 6: // EXTDATE (deprecated)
            // TODO [deprecate completely]
            $type = 'hidden';
            break;

        case 7: // MULTICHECKBOX
            $type = 'multicheckbox';
            $render->assign('value', (array)unserialize($uservalue));

            $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item));

            $render->assign('fields', $options);
            break;

        default: // TEXT
            $type = 'text';
            break;
    }

    return $render->fetch('profile_dudedit_'.$type.'.tpl');
}
コード例 #6
0
ファイル: Admin.php プロジェクト: projectesIF/Sirius
    public function summary($args) {
        // get the last record in summary table
        $table = DBUtil::getTables();
        $c = $table['IWstats_summary_column'];
        $d = $table['IWstats_column'];

        // get first record datetime
        $orderby = "$d[summarised] asc";
        $last = DBUtil::selectObjectArray('IWstats', '', $orderby, -1, 1);

        $time = DateUtil::makeTimestamp($last[0]['datetime']);
        $toDateTimeStamp = $time + $args['days'] * 24 * 60 * 60;
        // calc the period
        $fromDate = date('d-m-Y', $time);
        $toDate = date('d-m-Y', $toDateTimeStamp);

        $records = ModUtil::apiFunc('IWstats', 'user', 'getAllRecords', array('fromDate' => $fromDate,
                    'toDate' => $toDate,
                    'all' => 1,
                ));

        $recordsArray = array();

        foreach ($records as $record) {
            if (key_exists(substr($record['datetime'], 0, 10), $recordsArray)) {
                // add new information in array element
                $recordsArray[substr($record['datetime'], 0, 10)]['nRecords']++;
                if (($record['uid'] > 0))
                    $recordsArray[substr($record['datetime'], 0, 10)]['registered']++;
                if (key_exists($record['moduleid'], $recordsArray[substr($record['datetime'], 0, 10)]['users'][$record['uid']]['modules'])) {
                    $recordsArray[substr($record['datetime'], 0, 10)]['users'][$record['uid']]['modules'][$record['moduleid']]++;
                } else {
                    // add a new user in users array field
                    $recordsArray[substr($record['datetime'], 0, 10)]['users'][$record['uid']]['modules'][$record['moduleid']] = 1;
                }
                if (key_exists($record['moduleid'], $recordsArray[substr($record['datetime'], 0, 10)]['modules'])) {
                    $recordsArray[substr($record['datetime'], 0, 10)]['modules'][$record['moduleid']]++;
                } else {
                    $recordsArray[substr($record['datetime'], 0, 10)]['modules'][$record['moduleid']] = 1;
                }
                if (($record['skipped'] == 1))
                    $recordsArray[substr($record['datetime'], 0, 10)]['skipped']++;
                if (($record['skippedModule'] == 1))
                    $recordsArray[substr($record['datetime'], 0, 10)]['skippedModule']++;
                if (($record['isadmin'] == 1))
                    $recordsArray[substr($record['datetime'], 0, 10)]['isadmin']++;
                if (!in_array($record['ip'], $recordsArray[substr($record['datetime'], 0, 10)]['ips'])) {
                    $recordsArray[substr($record['datetime'], 0, 10)]['ips'][] = $record['ip'];
                }
            } else {
                // add a new element into the array
                $recordsArray[substr($record['datetime'], 0, 10)]['nRecords'] = 1;
                $recordsArray[substr($record['datetime'], 0, 10)]['registered'] = ($record['uid'] > 0) ? 1 : 0;
                $recordsArray[substr($record['datetime'], 0, 10)]['users'][$record['uid']]['modules'][$record['moduleid']] = 1;
                $recordsArray[substr($record['datetime'], 0, 10)]['ips'][] = $record['ip'];
                $recordsArray[substr($record['datetime'], 0, 10)]['datetime'] = substr($record['datetime'], 0, 10) . ' 00:00:00';
                $recordsArray[substr($record['datetime'], 0, 10)]['modules'][$record['moduleid']] = 1;
                $recordsArray[substr($record['datetime'], 0, 10)]['skipped'] = ($record['skipped'] == 1) ? 1 : 0;
                $recordsArray[substr($record['datetime'], 0, 10)]['skippedModule'] = ($record['skippedModule'] == 1) ? 1 : 0;
                $recordsArray[substr($record['datetime'], 0, 10)]['isadmin'] = ($record['isadmin'] == 1) ? 1 : 0;
            }
        }

        ksort($recordsArray);

        // print_r($recordsArray);die();
        // save records in ddbb
        foreach ($recordsArray as $record) {
            $usersArray = array();
            foreach ($record['users'] as $key => $value) {
                $usersString = $key . '|';
                $usersModulesArray = array();
                foreach ($value['modules'] as $k => $v) {
                    $usersModulesArray[] = $k . '=' . $v;
                }
                $usersModulesString = implode('#', $usersModulesArray);
                $usersArray[] = $usersString . $usersModulesString;
            }

            $users = '$' . implode('$$', $usersArray) . '$';

            $modulesArray = array();
            foreach ($record['modules'] as $key => $value) {
                $modulesArray[] = $key . '|' . $value;
            }

            $modules = '$' . implode('$$', $modulesArray) . '$';

            $item = array(
                'datetime' => $record['datetime'],
                'nrecords' => $record['nRecords'],
                'registered' => $record['registered'],
                'modules' => $modules,
                'skipped' => $record['skipped'],
                'skippedModule' => $record['skippedModule'],
                'isadmin' => $record['isadmin'],
                'users' => $users,
                'nips' => count($record['ips']),
            );

            // checks if value exists in database. If exists update it. If not create it
            $summaryValue = DBUtil::selectObject('IWstats_summary', "$c[datetime]='$record[datetime]'");

            if ($summaryValue) {
                if (!DBUtil::updateObject($item, 'IWstats_summary', "$c[datetime]='$record[datetime]'")) {
                    return LogUtil::registerError($this->__('Error! Creation attempt failed.'));
                }
            } else {
                if (!DBUtil::insertObject($item, 'IWstats_summary')) {
                    return LogUtil::registerError($this->__('Error! Creation attempt failed.'));
                }
            }

            $keepDays = $this->getVar('keepDays');

            if (!is_numeric($keepDays) || $keepDays <= 0)
                $keepDays = 90;

            $time = time() - $keepDays * 24 * 60 * 60;
            $keepTime = date('Y-m-d 23:59:59', $time);
            $delDate = str_replace('00:00:00', '23:59:59', $record['datetime']);

            // set records as summarised
            $item = array('summarised' => 1);
            $where = "$d[datetime] <= '$delDate'";
            DBUtil::updateObject($item, 'IWstats', $where);

            // delete old records
            $where = "$d[datetime] <= '$delDate' and $d[datetime] <= '$keepTime'";
            DBUtil::deleteWhere('IWstats', $where);
        }

        return true;
    }
コード例 #7
0
ファイル: User.php プロジェクト: projectesIF/Sirius
    /**
     * Show bookings monthly view
     * @author	Albert Pérez Monfort (aperezm@xtec.cat)
     * @author	Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return	The renderized information
     */
    public function monthlyview($args) {
        // Security check
        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }

        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'GET');
        $year = FormUtil::getPassedValue('year', isset($args['year']) ? $args['year'] : null, 'GET');
        $month = FormUtil::getPassedValue('month', isset($args['month']) ? $args['month'] : null, 'GET');
        $inc = FormUtil::getPassedValue('m', isset($args['m']) ? $args['m'] : 0, 'GET');

        $aux_month = (int) DateUtil::getDatetime('', '%m');
        $aux_year = (int) DateUtil::getDatetime('', '%Y');

        if (empty($year) or empty($month)) {
            $year = DateUtil::getDatetime('', '%Y');
            $month = $aux_month;
        } else {
            $month = $month + $inc;
        }

        if ($month == 0) {
            $month = 12;
            $year = $year - 1;
        }
        if ($month == 13) {
            $month = 1;
            $year = $year + 1;
        }

        if (($month < $aux_month) && ($year == $aux_year)) {
            $month = $aux_month;
        } //Minim month is current month
        //Memoritzem un array amb els dies de la setmana
        // Create an array with the days of the week
        $showWeekends = ModUtil::getVar('IWbookings', 'weekends');
        if ($showWeekends) {
            $days = array($this->__('Monday'),
                $this->__('Tuesday'),
                $this->__('Wednesday'),
                $this->__('Thursday'),
                $this->__('Friday'),
                $this->__('Saturday'),
                $this->__('Sunday'));
        } else {
            $days = array($this->__('Monday'),
                $this->__('Tuesday'),
                $this->__('Wednesday'),
                $this->__('Thursday'),
                $this->__('Friday'));
        }
        //Array with the name of the months
        $monthNames = array('', $this->__('January'),
            $this->__('February'),
            $this->__('March'),
            $this->__('April'),
            $this->__('May'),
            $this->__('June'),
            $this->__('July'),
            $this->__('August'),
            $this->__('September'),
            $this->__('October'),
            $this->__('November'),
            $this->__('December'));

        // Get month days number
        $numDays = count(DateUtil::getMonthDates($month, $year));
        // First day of month
        $startDate = DateUtil::buildDatetime($year, $month, 1, 0, 0, 0);
        // last day of month
        $endDate = DateUtil::buildDatetime($year, $month, $numDays, 23, 59, 59);

        //determinem quin dia de la setmana �s el primer dia del mes
        // Get the fisrt day of week of the month
        $firstDay = date("w", DateUtil::makeTimestamp($startDate));

        //per si el primer dia del mes �s diumenge el posem a 7, ja que en aquest cas PHP retorna el valor 0
        ($firstDay == 0) ? $firstDay = 7 : "";

        //Situem els espais de reserva en un camp multiselect des d'on es podran filtra les dades dels espais
        //Cridem la funci� API que retornar� la informaci� de tots els espais de reserva definits
        $espais[] = array('id' => -1, 'name' => $this->__('All rooms and equipments'));
        $registres = ModUtil::apiFunc('IWbookings', 'user', 'getall');

        foreach ($registres as $registre) {
            if ($registre['active'] == 1) {
                $espais[] = array('id' => $registre['sid'],
                    'name' => $registre['space_name']);
                $space_info[$registre['sid']]['name'] = $registre['space_name'];
                $space_info[$registre['sid']]['color'] = $registre['color'];
            }
        }

        $taula = array();
        //Blanc spaces in calendar
        for ($j = 1; $j < $firstDay; $j++) {
            if ($showWeekends || ($firstDay != 7 && $firstDay != 6)) {
                $table[] = '';
            }
        }
        $n_col = 0;
        for ($i = 1; $i <= $numDays; $i++) {
            ($n_col % 7 == 1) ? $table[] = array('space_name' => '') : "";
            $dia = (date("w", mktime(0, 0, 0, $month, $i, $year)) + 7) % 7;
            if ($i <= $numDays && (($dia != 6 && $dia != 0) || ModUtil::getVar('IWbookings', 'weekends'))) {
                //Determinem el per�ode de les dades de les reserves
                $start = DateUtil::buildDatetime($year, $month, $i, 0, 0, 0);
                $end = DateUtil::buildDatetime($year, $month, $i, 23, 59, 59);
                $dow = date("w", DateUtil::makeTimestamp($start));
                ($dow == 0) ? $dow = 7 : "";
                //Agafem les reserves puntuals
                //Obtenim les reserves d'un dia per a un determinat espai o tots (sid = -1)
                // Take the non permanent books
                $bookings = ModUtil::apiFunc('IWbookings', 'user', 'getall_reserves', array('sid' => $sid,
                            'from' => $start,
                            'to' => $end,
                            'dw' => $dow));

                //Afegim a la matriu reserves les dades de les reserves temporals amb hores d'inici i final coincidents
                // Add to bookings array the permenent books which has the same start and end period hours
                $reserva = array();
                if (empty($bookings)) {
                    $reserva['day'] = $i;
                    $table[$i + $firstDay][][] = $reserva;
                } else {
                    foreach ($bookings as $booking) {
                        // $i is the current day of the month
                        $reserva['date'] = date('d-m-y', strtotime($start));
                        $reserva['day'] = $i;
                        $reserva['sid'] = $booking['sid'];
                        $reserva['bid'] = $booking['bid'];
                        $reserva['grup'] = $booking['grup'];
                        $reserva['space'] = (isset($booking['sid'])) ? $space_info[$booking['sid']]['name'] : '';
                        $reserva['color'] = (isset($booking['sid'])) ? $space_info[$booking['sid']]['color'] : '';
                        $reserva['temp'] = $booking['temp'];
                        $booking['usuari'] = (!isset($booking['usuari'])) ? 0 : $booking['usuari'];

                        if ((($booking['usuari'] == UserUtil::getVar('uid')))
                                or (SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADMIN))) {

                            $reserva['candelete'] = true;
                        } else {
                            $reserva['candelete'] = false;
                        }

                        $reserva['hour'] = date('H:i', strtotime($booking['inici'])) . "-" . date('H:i', strtotime($booking['final']));
                        if ($booking['usuari'] > 0) {
                            $reserva['uname'] = ModUtil::func('IWmain', 'user', 'getUserInfo', array('uid' => $booking['usuari'],
                                        'sv' => ModUtil::func('IWmain', 'user', 'genSecurityValue'),
                                        'info' => 'u'));
                            $reserva['user'] = ModUtil::func('IWmain', 'user', 'getUserInfo', array('uid' => $booking['usuari'],
                                        'sv' => ModUtil::func('IWmain', 'user', 'genSecurityValue'),
                                        'info' => 'ncc'));
                        } else {
                            $reserva['uname'] = '';
                            $reserva['user'] = '';
                        }

                        $reserva['shortuname'] = mb_strimwidth($reserva['user'], 0, 22, '');
                        // Prepare book info output
                        $contingut = '<em><b><font color=red>' . $reserva['space'] . '</font></b></em><br>';
                        ($booking['temp'] == 1) ? $contingut.='<b><font color=green>' . $this->__('Preferential') . '</font></b><br>' : "";
                        $contingut.= $this->__('Teacher') . $reserva['user'];
                        $contingut.='<br>' . $this->__('Group: ') . $booking['grup'];
                        ($booking['motiu'] == "") ? $motiu = '---' : $motiu = '<br>' . $booking['motiu'];
                        $contingut.='<br>' . $this->__('Reason for booking') . $motiu;




                        $contingut = ModUtil::func('IWbookings', 'user', 'prepara_etiqueta', array('text' => $contingut));
                        $reserva['contingut'] = $contingut;
                        //$table[$i+$firstDay][$booking['sid']][]= $reserva; //Order by space
                        $table[$i + $firstDay][$i][] = $reserva; //Order by start time
                    }
                }
            }
        }

        if ($showWeekends) {
            $width = round((100 / 7));
            $tablerowlength = 7;
        } else {
            $width = round((100 / 5));
            $tablerowlength = 5;
        }

        return $this->view->assign('width', 200)
                        ->assign('month', $month)
                        ->assign('monthNames', $monthNames)
                        ->assign('year', $year)
                        ->assign('space_info', $space_info) // name and color. Array index = space sid
                        ->assign('days', $days)
                        ->assign('sid', $sid)
                        ->assign('diesdelmes', $numDays)
                        ->assign('firstDay', $firstDay - 1) // 1-> monday, 2-> tuesday, ... 7-> sunday
                        ->assign('spaces', $espais) // Listbox for selection purposes
                        ->assign('table', $table)
                        ->assign('tablerowlength', $tablerowlength)
                        ->fetch('IWbookings_user_monthly_view.htm');
    }
コード例 #8
0
ファイル: User.php プロジェクト: projectesIF/Sirius
    /**
     * Calcula la data inicial de la setmana a la qual pertany una determinada data
     * @author	Josep Ferr�ndiz Farr� (jferran6@xtec.cat)
     * @args The date (a MySQL timestamp or a string)
     * @return	the start date of the week
     */
    public function getWeek($args) {
        $TheDate = FormUtil::getPassedValue('date', isset($args['date']) ? $args['date'] : null, 'GET');
        $format = FormUtil::getPassedValue('format', isset($args['format']) ? $args['format'] : null, 'GET');

        $week = array();

        if (!SecurityUtil::checkPermission('IWbookings::', '::', ACCESS_READ)) {
            return $week;
        }

        $avui = DateUtil::makeTimestamp($TheDate);
        $dow = date("w", $avui);
        ($dow == 0) ? $dow = 7 : ""; // If sunday
        $fields = explode('-', $TheDate);


        if ($format == 'ymd') {
            $week['start'] = DateUtil::getDatetime_NextDay((1 - $dow), '%Y-%m-%d', $fields[0], $fields[1], $fields[2]);
            $week['end'] = DateUtil::getDatetime_NextDay((7 - $dow), "%Y-%m-%d %H:%M:%S", $fields[0], $fields[1], $fields[2], 23, 59, 59);
        } else {
            $week['start'] = DateUtil::getDatetime_NextDay((1 - $dow), '%d-%m-%y', $fields[0], $fields[1], $fields[2]);
            $week['end'] = DateUtil::getDatetime_NextDay((7 - $dow), "%d-%m-%y", $fields[0], $fields[1], $fields[2]);
        }
        return $week;
    }