Upload docs draft
This commit is contained in:
@@ -129,9 +129,9 @@ class Auth extends PhpObject
|
||||
//Reset pass once a day
|
||||
if(mb_substr($asEmpl['led'], 0, 10) != date('Y-m-d')) $this->resetAuthCookie($this->getUserId());
|
||||
}
|
||||
else $this->addError('token corrompu pour le user '.$asEmpl[Db::getId(self::USER_TABLE)]);
|
||||
else $this->addError('corrupted token for user '.$asEmpl[Db::getId(self::USER_TABLE)]);
|
||||
}
|
||||
else $this->addError('Utilisateur '.$iUserId.' inconnu');
|
||||
else $this->addError('Unknown user '.$iUserId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
inc/catc.php
59
inc/catc.php
@@ -13,7 +13,8 @@ class CATC extends Main
|
||||
$asClasses = array(
|
||||
array('name'=>'auth', 'project'=>true),
|
||||
array('name'=>'course', 'project'=>true),
|
||||
array('name'=>'note', 'project'=>true)
|
||||
array('name'=>'note', 'project'=>true),
|
||||
array('name'=>'doc', 'project'=>true)
|
||||
);
|
||||
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
|
||||
|
||||
@@ -38,7 +39,7 @@ class CATC extends Main
|
||||
Course::WS_TABLE => array('dates'),
|
||||
Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'),
|
||||
'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
'docs' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'path'),
|
||||
Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'),
|
||||
'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
|
||||
),
|
||||
'types' => array
|
||||
@@ -52,40 +53,15 @@ class CATC extends Main
|
||||
'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')",
|
||||
'notes' => "LONGTEXT",
|
||||
'type' => "VARCHAR(10)",
|
||||
'path' => "VARCHAR(100)"
|
||||
'filename' => "VARCHAR(200)"
|
||||
),
|
||||
'constraints' => array
|
||||
(
|
||||
'docs' => "UNIQUE KEY `uni_path` (`path`)"
|
||||
Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getPage()
|
||||
{
|
||||
//Constants
|
||||
$asGlobalVars = array(
|
||||
'consts' => array(
|
||||
'token_sep' => Auth::TOKEN_SEP,
|
||||
'error' => self::ERROR,
|
||||
'success' => self::SUCCESS,
|
||||
'context' => $this->asContext,
|
||||
'cookie' => Auth::USER_COOKIE_PASS
|
||||
),
|
||||
'vars' => $this->getVars()
|
||||
);
|
||||
|
||||
//Pages
|
||||
$asPages = array('logon', 'logoff', 'template', 'workshops', 'course');
|
||||
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
|
||||
|
||||
//Main Page
|
||||
//TODO use getMainPage parent function
|
||||
$sPage = $this->getPageContent('index');
|
||||
$sPage = str_replace('asGlobalVars', json_encode($asGlobalVars), $sPage);
|
||||
return $sPage;
|
||||
}
|
||||
|
||||
private function getVars() {
|
||||
return array(
|
||||
'id' => $this->oAuth->getUserId(),
|
||||
@@ -93,22 +69,24 @@ class CATC extends Main
|
||||
);
|
||||
}
|
||||
|
||||
public function getMainPage($asGlobalVars = array(), $sMainPage = 'index', $asMainPageTags=array())
|
||||
public function getAppMainPage()
|
||||
{
|
||||
return parent::getMainPage(
|
||||
return self::getMainPage(
|
||||
array(
|
||||
'consts' => array(
|
||||
'token_sep' => Auth::TOKEN_SEP,
|
||||
'error' => self::ERROR,
|
||||
'success' => self::SUCCESS,
|
||||
'context' => $this->asContext,
|
||||
'cookie' => Auth::USER_COOKIE_PASS
|
||||
'cookie' => Auth::USER_COOKIE_PASS,
|
||||
'courses' => (new Course($this->oDb))->getCourses()
|
||||
),
|
||||
'vars' => $this->getVars()
|
||||
),
|
||||
'index',
|
||||
array(
|
||||
'host_url' => $this->asContext['serv_name']
|
||||
'filepath_css' => self::addTimestampToFilePath('style/catc.css'),
|
||||
'filepath_js_catc' => self::addTimestampToFilePath('scripts/catc.js')
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -164,13 +142,20 @@ class CATC extends Main
|
||||
return self::getJsonResult($bSuccess, $sError, $asData);
|
||||
}
|
||||
|
||||
/*
|
||||
public function upload()
|
||||
/* Docs */
|
||||
|
||||
public function getDocs($iCourseId) {
|
||||
$oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$asDocList = $oDoc->getList();
|
||||
return self::getJsonResult(!empty($asDocList), '', $asDocList);
|
||||
}
|
||||
|
||||
public function uploadDoc($iCourseId)
|
||||
{
|
||||
$this->oClassManagement->incClass('uploader', true);
|
||||
$oUploader = new Uploader($this->oMedia);
|
||||
$oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$oUploader = new Uploader($oDoc);
|
||||
|
||||
return $oUploader->sBody;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -43,4 +43,11 @@ class Course extends PhpObject {
|
||||
|
||||
return $asWorkshops;
|
||||
}
|
||||
|
||||
public function getCourses($iWorkshopId=0) {
|
||||
$asInfo = array('select'=> array(Db::getId(self::COURSE_TABLE), 'description', 'timeslot'), 'from' => self::COURSE_TABLE);
|
||||
if($iWorkshopId > 0) $asInfo['constraint'] = array(Db::getId(self::WS_TABLE) => $iWorkshopId);
|
||||
|
||||
return $this->oDb->selectRows($asInfo, Db::getId(self::COURSE_TABLE));
|
||||
}
|
||||
}
|
||||
71
inc/doc.php
Normal file
71
inc/doc.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Doc extends PhpObject {
|
||||
|
||||
const DOC_FOLDER = 'files/';
|
||||
const DOC_TABLE = 'docs';
|
||||
/**
|
||||
* DB
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
|
||||
private $iDocId;
|
||||
private $iUserId;
|
||||
private $iCourseId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId, $iCourseId)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setDocId(0);
|
||||
$this->setUserCourseId($iUserId, $iCourseId);
|
||||
}
|
||||
|
||||
public function setDocId($iDocId) {
|
||||
$this->iDocId = $iDocId;
|
||||
}
|
||||
|
||||
public function setUserCourseId($iUserId, $iCourseId) {
|
||||
$this->iUserId = $iUserId;
|
||||
$this->iCourseId = $iCourseId;
|
||||
}
|
||||
|
||||
public function exists($sFileName) {
|
||||
return file_exists(self::DOC_FOLDER.$sFileName);
|
||||
}
|
||||
|
||||
public function add($sFileName, $sMimeType) {
|
||||
$sType = '';
|
||||
switch(mime_content_type(self::getFilePath($sFileName))) {
|
||||
case 'application/msword':
|
||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': $sType = 'word'; break;
|
||||
case 'application/pdf': $sType = 'pdf'; break;
|
||||
case 'audio/mpeg': $sType = 'audio'; break;
|
||||
case 'image/gif': $sType = 'image'; break;
|
||||
case 'image/jpeg': $sType = 'image'; break;
|
||||
case 'image/png': $sType = 'image'; break;
|
||||
}
|
||||
|
||||
$asData = array_merge($this->getDocKeys(), array('filename'=>$sFileName, 'type'=>$sType));
|
||||
|
||||
$bResult = $this->oDb->insertRow(self::DOC_TABLE, $asData);
|
||||
return $bResult?'':'error_db';
|
||||
}
|
||||
|
||||
public function delete($sFileName) {
|
||||
|
||||
}
|
||||
|
||||
public function getList() {
|
||||
return $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraints'=>$this->getDocKeys()));
|
||||
}
|
||||
|
||||
private function getDocKeys() {
|
||||
return array(Db::getId(Auth::USER_TABLE) => $this->iUserId, Db::getId(Course::COURSE_TABLE) => $this->iCourseId);
|
||||
}
|
||||
|
||||
private static function getFilePath($sFileName) {
|
||||
return self::DOC_FOLDER.$sFileName;
|
||||
}
|
||||
}
|
||||
1517
inc/uploader.php
Normal file
1517
inc/uploader.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user