Ejemplo n.º 1
0
 /**
  * Check if the attach step is completed
  *
  * @param   integer  $id  Resource ID
  * @return  boolean  True if step completed
  */
 public function step_attach_check($id)
 {
     if ($id) {
         $database = App::get('db');
         $ra = new \Components\Resources\Tables\Assoc($database);
         $total = $ra->getCount($id);
     } else {
         $total = 0;
     }
     return $total ? true : false;
 }
Ejemplo n.º 2
0
 /**
  * Save an attachment
  *
  * @return     void
  */
 public function saveTask()
 {
     // Incoming
     $pid = Request::getInt('pid', 0);
     if (!$pid) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // get tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolIdFromResource($pid);
     // make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_FILE'));
         $this->displayTask($pid);
         return;
     }
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     // Ensure file names fit.
     $ext = Filesystem::extension($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     if (strlen($file['name']) > 230) {
         $file['name'] = substr($file['name'], 0, 230);
         $file['name'] .= '.' . $ext;
     }
     // Instantiate a new resource object
     $row = new \Components\Resources\Tables\Resource($this->database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     $row->title = $row->title ? $row->title : $file['name'];
     $row->introtext = $row->title;
     $row->created = Date::toSql();
     $row->created_by = User::get('id');
     $row->published = 1;
     $row->publish_up = Date::toSql();
     $row->publish_down = '0000-00-00 00:00:00';
     $row->standalone = 0;
     $row->access = 0;
     $row->path = '';
     // make sure no path is specified just yet
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     if (!$row->id) {
         $row->id = $row->insertid();
     }
     // Build the path
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $listdir = \Components\Resources\Tables\Html::build_path($row->created, $row->id, '');
     $path = $this->_buildUploadPath($listdir, '');
     // Make sure the upload path exist
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH'));
             $this->displayTask($pid);
             return;
         }
     }
     // Perform the upload
     if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_UPLOADING'));
     } else {
         // File was uploaded
         // Check the file type
         $row->type = $this->_getChildType($file['name']);
     }
     if (!$row->path) {
         $row->path = $listdir . DS . $file['name'];
     }
     if (substr($row->path, 0, 1) == DS) {
         $row->path = substr($row->path, 1, strlen($row->path));
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     // Instantiate a Resources Assoc object
     $assoc = new \Components\Resources\Tables\Assoc($this->database);
     // Get the last child in the ordering
     $order = $assoc->getLastOrder($pid);
     $order = $order ? $order : 0;
     // Increase the ordering - new items are always last
     $order = $order + 1;
     // Create new parent/child association
     $assoc->parent_id = $pid;
     $assoc->child_id = $row->id;
     $assoc->ordering = $order;
     $assoc->grouping = 0;
     if (!$assoc->check()) {
         $this->setError($assoc->getError());
     }
     if (!$assoc->store(true)) {
         $this->setError($assoc->getError());
     }
     $this->_rid = $pid;
     // Push through to the attachments view
     $this->displayTask($pid);
 }
Ejemplo n.º 3
0
        echo Lang::txt('Title');
        ?>
</th>
						<th scope="col" colspan="3"><?php 
        echo Lang::txt('Associations');
        ?>
</th>
						<th scope="col" colspan="2"><?php 
        echo Lang::txt('Status');
        ?>
</th>
					</tr>
				</thead>
				<tbody>
				<?php 
        $ra = new \Components\Resources\Tables\Assoc($database);
        $rc = new \Components\Resources\Tables\Contributor($database);
        $cls = 'even';
        foreach ($submissions as $submission) {
            $cls = $cls == 'even' ? 'odd' : 'even';
            switch ($submission->published) {
                case 1:
                    $state = 'published';
                    break;
                    // published
                // published
                case 2:
                    $state = 'draft';
                    break;
                    // draft
                // draft
Ejemplo n.º 4
0
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
$attachments = 0;
$authors = 0;
$tags = array();
$state = 'pending';
$type = '';
if ($this->resource->id) {
    $database = App::get('db');
    $ra = new \Components\Resources\Tables\Assoc($database);
    $rc = new \Components\Resources\Tables\Contributor($database);
    $rt = new \Components\Resources\Helpers\Tags($this->resource->id);
    switch ($this->resource->published) {
        case 1:
            $state = 'published';
            break;
            // published
        // published
        case 2:
            $state = 'draft';
            break;
            // draft
        // draft
        case 3:
            $state = 'pending';