예제 #1
0
파일: User.php 프로젝트: etienne/jam
 function Logout()
 {
     if (Cookie::Delete('id')) {
         HTTP::RedirectLocal();
         return true;
     } else {
         return false;
     }
 }
예제 #2
0
 function PagesViewController()
 {
     if ($_GET['m'] == 'updated') {
         HTTP::RedirectLocal('merci');
         return false;
     }
     $this->view['form'] = $this->GetForm();
     $themes = Module::GetNewModule('themes');
     $queryParams = array('fields' => 'titreCourt', 'orderby' => 'sortIndex');
     $themes->FetchItems($queryParams);
     $this->view['themes'] = $themes->items;
 }
예제 #3
0
파일: init.php 프로젝트: noix/programme
<?php

if ($_GET['m'] == 'updated') {
    HTTP::RedirectLocal('merci');
}
$_JAG['snippets']['titre'] = "Formulaire de participation";
예제 #4
0
파일: adminModule.php 프로젝트: etienne/jam
 function AdminListViewController()
 {
     global $_JAM;
     if (!($fields = $this->nestedModule->config['adminListFields'])) {
         foreach ($this->nestedModule->schema as $name => $info) {
             if (!$_JAM->moduleFields[$name] && !$_JAM->versionsSupportFields[$name]) {
                 $fields[] = $name;
             }
         }
     }
     // Add sortIndex field if we require it
     if ($this->nestedModule->config['allowSort']) {
         array_unshift($fields, 'sortIndex');
     }
     // Link will be on first field; we do this before adding sortIndex because we never want the link on sortIndex (FIXME, FAUX)
     $this->nestedModule->view['linkField'] = reset($fields);
     foreach ($fields as $field) {
         if ($relatedArray = $this->nestedModule->GetRelatedArray($field)) {
             $this->nestedModule->view['relatedArrays'][$field] = $relatedArray;
         }
     }
     $queryParams['fields'] = $fields;
     $this->nestedModule->view['tableFields'] = $fields;
     // Determine header strings
     foreach ($fields as $field) {
         // Look for string in module strings
         if (!($string = $this->nestedModule->strings['fields'][$field])) {
             // Look for string in global strings
             if (!($string = $_JAM->strings['fields'][$field])) {
                 // Use raw field name if all else fails
                 $string = $field;
             }
         }
         $this->nestedModule->view['headerStrings'][$field] = $string;
     }
     // Determine sort order
     $requestedSortField = $_GET['s'] ? $_GET['s'] : $this->nestedModule->config['adminListSortBy'];
     if ($this->nestedModule->schema[$requestedSortField] && in_array($requestedSortField, $fields)) {
         $sortField = $requestedSortField;
     } else {
         // If no sorting was requested, use first field
         $sortField = reset($fields);
     }
     // Determine type of sort field
     $this->nestedModule->view['sortFieldType'] = $this->nestedModule->schema[$sortField]['type'];
     // Check whether sorting order should be reversed
     $reverseSort = $_GET['r'] ? 1 : 0;
     // Store sort parameters in template variables
     $this->nestedModule->view['sortField'] = $sortField;
     $this->nestedModule->view['reverseSort'] = $reverseSort;
     // Sort order is reversed for dates
     if ($this->nestedModule->schema[$sortField]['type'] == 'datetime') {
         $reverseSort = (int) (!$reverseSort);
     }
     // Modify query accordingly
     $sortOrder = $reverseSort ? 'DESC' : 'ASC';
     $queryParams['orderby'][] = $sortField . ' ' . $sortOrder;
     // Try to sort by sort index when allowSort is set
     if ($this->nestedModule->config['allowSort'] && $sortField != 'sortIndex') {
         $queryParams['orderby'][] = 'sortIndex ASC';
     }
     // Fetch data
     $this->nestedModule->FetchItems($queryParams);
     if ($this->nestedModule->items) {
         $editLinkPrefix = 'admin/' . $this->nestedModule->name . '?' . ($_GET['s'] ? 's=' . $_GET['s'] . '&amp;' : '') . ($_GET['r'] ? 'r=' . $_GET['r'] . '&amp;' : '') . 'a=edit&amp;id=';
         // Redirect to item if requested
         if ($_GET['prev'] || $_GET['next']) {
             $requestedID = $_GET['prev'] ? $_GET['prev'] : $_GET['next'];
             // Find primary key column name
             if ($this->nestedModule->config['keepVersions']) {
                 $primaryKey = 'master';
             } else {
                 $primaryKey = 'id';
             }
             // Find key for requested item in fetched items array
             foreach ($this->nestedModule->items as $key => $item) {
                 if ($item[$primaryKey] == $requestedID) {
                     $requestedKey = $key;
                     break;
                 }
             }
             // Find ID for requested item
             $previousAndNext = Arrays::GetAdjacentKeys($this->nestedModule->items, $requestedKey);
             if ($_GET['prev']) {
                 $redirectID = $this->nestedModule->items[$previousAndNext[0]][$primaryKey];
             }
             if ($_GET['next']) {
                 $redirectID = $this->nestedModule->items[$previousAndNext[1]][$primaryKey];
             }
             // Redirect to requested item
             if ($redirectID) {
                 // Change "&amp;" to "&"; slightly kludgy
                 $cleanLink = html_entity_decode($editLinkPrefix . $redirectID);
                 // Add mode if one was supplied (kludgy)
                 if ($_GET['mode']) {
                     $cleanLink .= '&mode=' . $_GET['mode'];
                 }
                 HTTP::RedirectLocal($cleanLink);
             }
         }
         // Store edit link prefix in template
         $this->nestedModule->view['editLinkPrefix'] = $editLinkPrefix;
     }
 }
예제 #5
0
파일: Jam.php 프로젝트: etienne/jam
 function FirstRun()
 {
     // Load table structure for required tables
     $tables = IniFile::Parse('engine/database/tables.ini', true);
     // Create tables
     foreach ($tables as $name => $schema) {
         if (!Database::CreateTable($name, $schema)) {
             trigger_error("Couldn't create table " . $name, E_USER_ERROR);
         }
     }
     // Manually add admin module to _modules table
     if (Query::TableIsEmpty('_modules')) {
         $adminModule = array('name' => 'admin');
         if (!Database::Insert('_modules', $adminModule)) {
             trigger_error("Couldn't install core modules", E_USER_ERROR);
         }
     }
     // Install required modules
     $requiredModules = array('users', 'files');
     foreach ($requiredModules as $moduleName) {
         $module = Module::GetNewModule($moduleName);
         $module->Install();
     }
     // Add default admin user
     if (Query::TableIsEmpty('users')) {
         $adminUserParams = array('created' => $this->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3);
         if (!Database::Insert('users', $adminUserParams)) {
             trigger_error("Couldn't create admin user", E_USER_ERROR);
         }
     }
     // Add admin path
     $adminModuleId = Query::SingleValue('_modules', 'id', "name = 'admin'");
     if (!Path::Insert('admin', $adminModuleId, false)) {
         trigger_error("Couldn't add admin path", E_USER_ERROR);
     }
     // Redirect to admin interface
     HTTP::RedirectLocal('admin');
 }
예제 #6
0
파일: Module.php 프로젝트: noix/qsprog
 function ProcessData()
 {
     global $_JAM;
     // Validate data; this fills $this->postData
     $this->ValidateData();
     // Display error and abort if there is invalid or missing data or a file upload error
     if ($this->invalidData || $this->missingData || $this->fileUploadError) {
         return false;
     }
     // Clear cache entirely; very brutal but will do for now
     $_JAM->cache->Clear();
     // Run custom action method if available
     if ($action = $_POST['action']) {
         $actionMethod = $action . 'Action';
         if (method_exists($this, $actionMethod)) {
             $this->{$actionMethod}();
             return true;
         } elseif ($this->parentModule->name == 'admin') {
             // We're in admin mode; look for action in admin module
             if (method_exists($this->parentModule, $actionMethod)) {
                 $this->parentModule->{$actionMethod}($this);
                 return true;
             }
         }
     }
     // Determine what we need to insert from what was submitted
     foreach ($this->schema as $name => $info) {
         // Omit fields which we can't edit
         if ($info['canEdit'] && !$_JAM->user->HasPrivilege($info['canEdit'])) {
             continue;
         }
         // Make sure data exists, and exclude 'multi' fields; we handle them later
         if (isset($this->postData[$name]) && $info['type'] != 'multi') {
             if ($info['localizable']) {
                 $localizedData[$name] = $this->postData[$name];
             } else {
                 $insertData[$name] = $this->postData[$name];
             }
         }
     }
     if (!$_GET['item']) {
         // FIXME: More kludge! Translations again.
         if (!$this->config['useCustomTable']) {
             // This is a standard table with special fields
             // If user is logged in, insert user ID
             if ($_JAM->user->id) {
                 $insertData['user'] = $_JAM->user->id;
             }
         }
         if (!$this->config['keepVersions']) {
             // Standard table; simple update
             if ($_POST['master']) {
                 // Update mode
                 $where = 'id = ' . $_POST['master'];
                 if (!$this->UpdateItems($insertData, $where)) {
                     // Update failed
                     trigger_error("Couldn't update module", E_USER_ERROR);
                     return false;
                 }
                 $insertID = $_POST['master'];
             } else {
                 // Post mode
                 if (!$this->config['useCustomTable']) {
                     $insertData['created'] = $_JAM->databaseTime;
                 }
                 if (!Database::Insert($this->name, $insertData)) {
                     trigger_error("Couldn't insert into module " . $this->name, E_USER_ERROR);
                     return false;
                 }
                 // Keep ID of inserted item for path
                 $insertID = Database::GetLastInsertID();
             }
         } else {
             // Special update for tables with multiple versions support
             // Set item as current
             $insertData['current'] = true;
             // If we already have a creation date and one wasn't specified, use that
             if (!$insertData['created'] && $this->item['created']) {
                 $insertData['created'] = $this->item['created'];
             }
             if (!Database::Insert($this->name, $insertData)) {
                 trigger_error("Couldn't insert into module " . $this->name, E_USER_ERROR);
             } else {
                 // Keep ID of inserted item for path
                 $insertID = Database::GetLastInsertID();
                 // $this->postData now represents actual data
                 $this->LoadData($this->postData);
                 // Disable all other items with the same master
                 if ($insertData['master']) {
                     $updateParams['current'] = false;
                     $whereArray = array(array('master = ' . $insertData['master'], 'id = ' . $insertData['master']), 'id != ' . $insertID);
                     $where = Database::GetWhereString($whereArray);
                     if (!Database::Update($this->name, $updateParams, $where)) {
                         trigger_error("Couldn't update module " . $this->name, E_USER_ERROR);
                         return false;
                     }
                 }
             }
         }
     } else {
         // FIXME: Kuldgy. Added to make translations work.
         $insertID = $_GET['item'];
     }
     // Insert localized data
     if ($localizedData) {
         $tableName = $this->name . '_localized';
         $localizedData['item'] = $insertID;
         $localizedData['language'] = $this->postData['language'];
         $where = array('item = ' . $insertID, "language = '" . $localizedData['language'] . "'");
         if (Database::Update($tableName, $localizedData, $where)) {
             // Insert if no rows were affected
             if (Database::GetModifiedRows() == 0) {
                 if (Database::Insert($tableName, $localizedData)) {
                     $success = true;
                 } else {
                     trigger_error("Couldn't insert localized data for module " . $this->name, E_USER_ERROR);
                 }
             } else {
                 $success = true;
             }
             // Put data into module object to reflect changes in the database
             if ($success) {
                 $this->LoadData($localizedData);
             }
         } else {
             trigger_error("Couldn't update localized data for module " . $this->name, E_USER_ERROR);
             return false;
         }
     }
     if ($insertID) {
         // Update path
         $this->UpdatePath($insertID);
         // Get ID for this item
         $id = $_POST['master'] ? $_POST['master'] : $insertID;
         // Delete previous many-to-many relationships
         $where = array('frommodule = ' . $this->moduleID, 'fromid = ' . $insertID);
         if (!Database::DeleteFrom('_relationships', $where)) {
             trigger_error("Couldn't delete previous many-to-many relationships for module " . $this->name, E_USER_ERROR);
         }
         foreach ($this->schema as $name => $info) {
             switch ($info['type']) {
                 case 'multi':
                     // Insert many-to-many relationships
                     foreach ($this->postData[$name] as $targetID) {
                         // Insert each item into _relationships table
                         $targetModuleName = $info['relatedModule'];
                         $targetModuleID = array_search($targetModuleName, $_JAM->installedModules);
                         $params = array('frommodule' => $this->moduleID, 'fromid' => $insertID, 'tomodule' => $targetModuleID, 'toid' => $targetID);
                         if (!Database::Insert('_relationships', $params)) {
                             trigger_error("Couldn't insert many-to-many relationship for module " . $this->name, E_USER_ERROR);
                         }
                     }
                     break;
             }
         }
     }
     if (method_exists($this, 'PostProcessData')) {
         $this->PostProcessData($insertID);
     }
     // Check whether we need to redirect to a specific anchor
     $anchor = $this->config['redirectToAnchor'][$this->parentModule->name];
     // Reload page
     if ($_JAM->rootModuleName == 'admin' || !$this->config['postSubmitRedirect']) {
         HTTP::ReloadCurrentURL('?m=updated' . ($anchor ? '#' . $anchor : ''));
     } else {
         HTTP::RedirectLocal($this->config['postSubmitRedirect']);
     }
 }
예제 #7
0
파일: firstrun.php 프로젝트: noix/programme
        trigger_error("Couldn't create table " . $name, E_USER_ERROR);
    }
}
// Manually add admin module to _modules table
if (Query::TableIsEmpty('_modules')) {
    $adminModule = array('name' => 'admin');
    if (!Database::Insert('_modules', $adminModule)) {
        trigger_error("Couldn't install core modules", E_USER_ERROR);
    }
}
// Install required modules
$requiredModules = array('users', 'files');
foreach ($requiredModules as $moduleName) {
    $module = Module::GetNewModule($moduleName);
    $module->Install();
}
// Add default admin user
if (Query::TableIsEmpty('users')) {
    $adminUserParams = array('created' => $_JAM->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3);
    if (!Database::Insert('users', $adminUserParams)) {
        trigger_error("Couldn't create admin user", E_USER_ERROR);
    }
}
// Add admin path
$adminModuleId = Query::SingleValue('_modules', 'id', "name = 'admin'");
if (!Path::Insert('admin', $adminModuleId, false)) {
    trigger_error("Couldn't add admin path", E_USER_ERROR);
}
// Redirect to admin interface
HTTP::RedirectLocal('admin');
예제 #8
0
 function PagesViewController()
 {
     if ($_GET['m'] == 'updated') {
         HTTP::RedirectLocal('merci');
         return false;
     }
     $this->view['form'] = $this->GetForm();
     // Add perspective specified as GET variable to form values
     $this->view['form']->LoadValue('perspective', $_GET['perspective']);
     $perspectives = Module::GetNewModule('perspectives');
     $queryParams = array('fields' => 'numero');
     $perspectives->FetchItems($queryParams);
     $this->view['perspectives'] = $perspectives->items;
     $themes = Module::GetNewModule('themes');
     $queryParams = array('orderby' => 'sortIndex');
     $themes->FetchItems($queryParams);
     $this->view['themes'] = $themes->items;
 }