MultiUpload module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
ziad
Forum Members
Forum Members
Posts: 16
Joined: Wed Apr 15, 2009 1:59 pm

MultiUpload module

Post by ziad »

Hi Everyone!

How do I use the MultiUpload module?

i can't seem to find the smarty tags in the help file.


Thanks,

Zi
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: MultiUpload module

Post by Dee »

I'm not familiar with it, but from the project description I understand the module is intended for use by other modules to provide multi-upload functionality.
Allowing an array of easier modules for uploading multiple files than provided with the core FileManager. Starting off with the postlet java-applet it will be extended with other systems that I find worth working on.
Regards,
D
ziad
Forum Members
Forum Members
Posts: 16
Joined: Wed Apr 15, 2009 1:59 pm

Re: MultiUpload module

Post by ziad »

Ahh i see

Thanks alot for your reply.

however, is there a way i can add the "upload file" ability to the feucalendar module?
i have all the functionality i need except fro uploading files which is essential for my project.

your help will be appreciated greatly!
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: MultiUpload module

Post by Dee »

Which version of Calendar are you using?
It seems FEUCalendar is an old, abandoned module, incompatible with the latest Calendar version (0.8.2).

I've updated the code so I can at least post a new event, but FEUCalender doesn't seem to have any functionality whatsoever to handle Calendar Custom (upload) Fields.

Regards,
D
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: MultiUpload module

Post by Dee »

Made some quick changes to the FeuCalendar module to make it work with Calendar-0.8.2 and add file inputs for any custom upload fields. See also attached module XML file (extension changed to .txt)

FeuCalendar.module.php

Code: Select all

<?php
#-------------------------------------------------------------------------
# FeuCalendar - Front End Users to Calendar bridge
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
# The module's homepage is: http://dev.cmsmadesimple.org/projects/feucalendar/
#-------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#-------------------------------------------------------------------------


class FeuCalendar extends CMSModule
{

  function GetName()
  {
    return get_class($this);
  }

  function GetFriendlyName()
  {
    return $this->Lang('friendlyname');
  }

  function GetVersion()
  {
    return '0.1';
  }

  function GetHelp()
  {
    return $this->Lang('help');
  }

  function GetAuthor()
  {
    return 'tamlyn';
  }

  function GetAuthorEmail()
  {
    return 'tam@zenology.co.uk';
  }

  function GetChangeLog()
  {
    return $this->Lang('changelog');
  }

  function IsPluginModule()
  {
    return true;
  }

  function HasAdmin()
  {
    return true;
  }

  function GetAdminSection()
  {
    return 'extensions';
  }

  function GetAdminDescription()
  {
    return $this->Lang('moddescription');
  }

  function VisibleToAdminUser()
  {
    return $this->CheckPermission('Modify Calendar');
  }

  function GetDependencies()
  {
    return array('FrontEndUsers' => '1.1.1', 'Calendar' => '0.7.3');
  }

  function MinimumCMSVersion()
  {
    return "1.0";
  }

  function InstallPostMessage()
  {
    return $this->Lang('postinstall');
  }

  function UninstallPostMessage()
  {
    return $this->Lang('postuninstall');
  }

  function UninstallPreMessage()
  {
    return false;//$this->Lang('really_uninstall');
  }

  function DoAction($action, $id, $params, $returnid=-1)
  {
    switch ($action)
    {
      case 'default' :
      case 'showform' :
        //show the form for adding new events
        if($this->CheckUser())
          $this->AddEventForm($id, $params, $returnid);
        else
          $this->DisplayMessage($id, $params, $returnid, $this->Lang('denied_title'), $this->Lang('denied_message'));
        break;
        
      case 'add_event' :
        //add the event submitted from the event form
        if($this->CheckUser())
          $this->AddEvent($id, $params, $returnid);
        else
          $this->DisplayMessage($id, $params, $returnid, $this->Lang('access_denied'));
        break;

      case 'defaultadmin' :
      case 'admin_prefs' :
        // only let people access module preferences if they have permission
        if ($this->CheckPermission('Modify Calendar'))
          $this->DisplayAdminPrefs($id, $params, $returnid);
        else
          $this->DisplayErrorPage($id, $params, $returnid,
              $this->Lang('accessdenied'));
        break;
        
      case 'save_admin_prefs':
        // only let people save module preferences if they have permission
        if ($this->CheckPermission('Modify Calendar'))
          $this->SaveAdminPrefs($id, $params, $returnid);

        break;
    }

  }


  function AddEventForm($id, $params, $returnid)
  {
    $calendar = $this->GetModuleInstance('Calendar');
    $event_id = -1;
    
    $this->smarty->assign('form_start', $this->CreateFormStart($id, 'add_event', $returnid, $method='post', $enctype='multipart/form-data',false,"",array()) . $this->CreateInputHidden($id, 'event_id', $event_id));
    $this->smarty->assign('form_end', $this->CreateFormEnd());
    
    $this->smarty->assign('form_submit', $this->CreateInputSubmit($id, '', $calendar->Lang('cal_add_event')));
    $this->smarty->assign('form_cancel', '<input type="button" value="'.$this->Lang('form_cancel').'" onclick="javascript:window.history.go(-1)" />');
    
    $this->smarty->assign('start_label', $calendar->Lang('cal_fromdate'));
    $this->smarty->assign('end_label', $calendar->Lang('cal_todate'));
    $this->smarty->assign('title_label', $calendar->Lang('cal_title'));
    $this->smarty->assign('summary_label', $calendar->Lang('cal_summary'));
    $this->smarty->assign('details_label', $calendar->Lang('cal_details'));
    $this->smarty->assign('categories_label', $calendar->Lang('cal_categories'));
    
    $current_year = date('Y');
    $start = $current_year - 2;
    $end = $current_year + 10;
    
    $year_array = array();
    for($i = $start; $i < $end; $i++) {
      $year_array[$i] = $i;
    }
    
    $month_array = array();
    for($i = 0; $i < 12; $i++) {
      $month_name = strftime('%b', mktime(12,0,0,$i+1,1));
      $month_number = sprintf('%02d', $i+1);
      $month_array[$month_name] = $month_number;
    }
    
    $day_array = array();
    for($i=1; $i < 32; $i++) {
      $day = sprintf('%02d', $i);
      $day_array[$i] = $day;
    }
    
    $hour_array = array();
    for($i=0; $i < 24; $i++) {
      $hour = sprintf('%02d', $i);
      if (1 == $calendar->GetPreference('use_twelve_hour_clock')) {
        if ($i >= 12) {
          if ($i == 12) {
            $hour_array[$i.' noon'] = $hour;
          } else {
            $pm_hour = $i - 12;
            $hour_array[$pm_hour.' p.m.'] = $hour;
          }
      
        } else {
          if ($i == 0)
            $hour_array['12 midnight'] = $hour;
          else
            $hour_array[$i.' a.m.'] = $hour;
        }
      } else {
        $hour_array[$hour] = $hour;
      }
    }

    $minute_array = array();
    for($i=0; $i < 60; $i++) {
      $minute = sprintf('%02d', $i);
      $minute_array[$minute] = $minute;
    }
    
    /*if(isset($event['event_date_start'])) {
      $event_date_start_time = strtotime($event['event_date_start']);
      $event_date_start_minute = date('i', $event_date_start_time);
      $event_date_start_hour = date('H', $event_date_start_time);
      $event_date_start_day = date('d', $event_date_start_time);
      $event_date_start_month = date('m', $event_date_start_time);
      $event_date_start_year = date('Y', $event_date_start_time);
    } else {
    */
      $event_date_start_minute = 0; //date('i');
      $event_date_start_hour = 0; //date('H');
      $event_date_start_day = date('d');
      $event_date_start_month = date('n');
      $event_date_start_year = $current_year;
    //}
    
    $this->smarty->assign('start_input', 
        $this->CreateInputDropdown($id, 'event_date_start_day', $day_array, -1, $event_date_start_day) .
        $this->CreateInputDropdown($id, 'event_date_start_month', $month_array, -1, $event_date_start_month) .
        $this->CreateInputDropdown($id, 'event_date_start_year', $year_array, -1, $event_date_start_year) .
        $this->Lang('date_time_separator') .
        $this->CreateInputDropdown($id, 'event_date_start_hour', $hour_array, -1, $event_date_start_hour) .
        $this->Lang('hour_minute_separator') .
        $this->CreateInputDropdown($id, 'event_date_start_minute', $minute_array, -1, $event_date_start_minute)
      );
    
    /*if(isset($event['event_date_end'])) {
      $event_date_end_time = strtotime($event['event_date_end']);
      $event_date_end_minute = date('i', $event_date_end_time);
      $event_date_end_hour = date('H', $event_date_end_time);
      $event_date_end_day = date('d', $event_date_end_time);
      $event_date_end_month = date('m', $event_date_end_time);
      $event_date_end_year = date('Y', $event_date_end_time);
    } else {
    */
      $event_date_end_minute = 0;
      $event_date_end_hour = 0;
      $event_date_end_day = 0;
      $event_date_end_month = 0;
      $event_date_end_year = 0;
    //}
    
    $day_array[''] = 0;
    $month_array[''] = 0;
    $year_array[''] = 0;
    asort($day_array);
    asort($month_array);
    asort($year_array);
    
    $this->smarty->assign('end_input', 
        $this->CreateInputDropdown($id, 'event_date_end_day', $day_array, -1, $event_date_end_day) .
        $this->CreateInputDropdown($id, 'event_date_end_month', $month_array, -1, $event_date_end_month) .
        $this->CreateInputDropdown($id, 'event_date_end_year', $year_array, -1, $event_date_end_year) .
        $this->Lang('date_time_separator') .
        $this->CreateInputDropdown($id, 'event_date_end_hour', $hour_array, -1, $event_date_end_hour) .
        $this->Lang('hour_minute_separator') .
        $this->CreateInputDropdown($id, 'event_date_end_minute', $minute_array, -1, $event_date_end_minute)
      );
    $custom_field_inputs = array();
    foreach($calendar->GetFields() as $field) {
        switch ($field['field_type'])
        {
            case '0': // text field
            break;
            case '1': // file upload field
                $safefieldname =  str_replace (" ", "_", $field['field_name']);
                $custom_field_inputs[]['label'] = $this->CreateLabelForInput($id, 'field_' . $safefieldname, $field['field_name']);
                $custom_field_inputs[]['input'] = $this->CreateFileUploadInput($id, 'field_' . $safefieldname) 
                . $this->CreateInputHidden($id, 'upload_field_' . $safefieldname, $field['field_name']);
            break;
        }
    }
    $this->smarty->assign('custom_field_inputs', $custom_field_inputs);

    $this->smarty->assign('title_input', $this->CreateInputText($id, 'event_title', $event['event_title'], 50, 50));
    $this->smarty->assign('summary_input', $this->CreateInputText($id, 'event_summary', $event['event_summary'], 50, 100));
    $this->smarty->assign('details_input', $this->CreateTextArea(true, $id, $event['event_details'], 'event_details', 'content', $id, '', '', 40, 10));
    
    $categories = $calendar->GetCategories();

    $num_cats = count($categories);
    $num_cols = 2;
    $rows_per_col = intval($num_cats / $num_cols);
    $count = 0;
    $cat_code = "";
    for($i = 0; $i < $num_cats; $i++,$count ++) {
      if($count >= $rows_per_col && $rows_per_col != 0) {
        $count = 0;
        $cat_code .= "</td><td valign='top' style='padding-left: 40px;' >\n";
        $padding = 0;
      }
    
      if($i < $num_cats) {
        $category = $categories[$i];
        $cat_id = $category['category_id'];
        $cat_name = $category['category_name'];
        $checked = '';
        //if(in_array($cat_id, $event['categories']))
        //  $checked = $cat_id;
        $cat_code .= "<div><label>";
        $cat_code .= $this->CreateInputCheckbox($id, 'event_categories[]', $cat_id, $checked);
        $cat_code .= $cat_name;
        $cat_code .= "</label></div>\n";
      }
    }
    $this->smarty->assign('categories_input', $cat_code);
    
    echo $this->ProcessTemplate("add_event.tpl");
  }

  function CreateTextArea($enablewysiwyg, $id, $text, $name, $classname='', $htmlid='', $encoding='', $stylesheet='', $width='80', $cols='15',$forcewysiwyg="")
  {
    return create_textarea($enablewysiwyg, $text, $id.$name, $classname, $htmlid, $encoding, $stylesheet, $width, $cols,$forcewysiwyg);
  }

  /**
   * Save the submitted event info by passing it to the calendar module
   */
  function AddEvent($id, &$params, $returnid) 
  {
    $calendar = $this->GetModuleInstance('Calendar');
    
    //set user_id to 0 since not an admin user
    $tmp = $this->cms->variables['user_id'];
    $this->cms->variables['user_id'] = 0;

    //add the event through the calendar module
    $calendar->DoAction('admin_event_update', $id, $params, $returnid);
    
    //set user_id back to whatever it was
    $this->cms->variables['user_id'] = $tmp;
    
    $this->DisplayMessage($id, $params, $returnid, $this->Lang('success_title'), $this->Lang('success_message'));
  }

  function DisplayAdminPrefs($id, &$params, $returnid, $message='')
  {
    $this->smarty->assign('mod_prefs_title', $this->Lang('mod_prefs_title'));
    
    $this->smarty->assign('form_start', $this->CreateFormStart($id, 'save_admin_prefs', $returnid, $method='post', $enctype='multipart/form-data'));
    $this->smarty->assign('form_end', $this->CreateFormEnd());
    $this->smarty->assign('form_submit', $this->CreateInputSubmit($id, 'form_submit', $this->Lang('form_submit')));

    // you'll often want to do things like this to provide feedback:
    $this->smarty->assign('message', (isset($params['message'])?$params['message']:''));
    
    //$wysiwygs = $this->GetWYSIWYGs();
    $feu = $this->GetModuleInstance('FrontEndUsers');
    $groups = $feu->GetGroupList();
    
 
    $this->smarty->assign('allow_guest_label', $this->Lang('allow_guest_label'));
    $this->smarty->assign('allow_guest_input', $this->CreateInputCheckbox($id, 'allow_guest', 1, $this->GetPreference('allow_guest', '0')));
    $this->smarty->assign('group_label', $this->Lang('group_label'));
    $this->smarty->assign('group_input', $this->CreateInputDropdown($id, 'group', $groups, -1, $this->GetPreference('group', '')));
    $this->smarty->assign('wysiwyg_label', $this->Lang('wysiwyg_label'));
    $this->smarty->assign('wysiwyg_input', 'None');//$this->CreateInputDropdown($id, 'wysiwyg_input', $day_array, -1, $event_date_end_day));
    
    
    echo $this->ProcessTemplate('admin.tpl');
  }
  
  /**
   * Get an array of all active wysiwyg modules
   */
  function GetWYSIWYGArray()
  {
    global $gCms;
    $module_list = array();
    foreach($gCms->modules as $key => $module)
      if($module['installed'] && $module['active'] && $module['object']->IsWYSIWYG())
        $module_list[] =& $gCms->modules[$key]['object']; //set reference to module object
    
    return $module_list;
  }

  function SaveAdminPrefs($id, &$params, $returnid)
  {
    $this->SetPreference('group', $params['group']);
    //$this->SetPreference('wysiwyg', $params['wysiwyg']);
    $this->SetPreference('allow_guest', isset($params['allow_guest'])?$params['allow_guest']:'0');

    // to call another method of the module, you have to be careful now that
    // methods can be split into other files. Here's the prefered approach:
    $params['message'] = $this->Lang('prefsupdated');
    $this->Redirect($id, 'defaultadmin', $returnid);
  }
  
  /**
   * Display a simple message
   */
  function DisplayMessage($id, &$params, $returnid, $title, $message)
  {
    $this->smarty->assign('title', $title);
    $this->smarty->assign('message', $message);

    echo $this->ProcessTemplate('message.tpl');
  }
  
  /**
   * Check if current user is allowed to post
   */
  function CheckUser()
  {
    $feu =& $this->GetModuleInstance('FrontEndUsers');
    
    if( $this->GetPreference('allow_guest') ||
        $feu->LoggedIn() &&
        $feu->MemberOfGroup($feu->LoggedInId(), $this->GetPreference('group')))
      return true;
    else {
      return false;
    }
  }

}

?>
templates/add_event.tpl

Code: Select all

{$form_start}
<table id="feucalendar-addevent" border="0" cellpadding="5" cellspacing="5">
  <tr>
    <td align="right">{$start_label}:</td> 
    <td>{$start_input}</td>
  </tr>
  <tr>
    <td align="right">{$end_label}:</td>
    <td>{$end_input}</td>
  </tr>
  <tr>
    <td align="right">{$title_label}:</td>
    <td>{$title_input}</td>
  </tr>
  <tr>
    <td align="right">{$summary_label}:</td>
    <td>{$summary_input}</td>
  </tr>
  <tr>
    <td align="right">{$details_label}:</td>
    <td>{$details_input}</td>
  </tr>
  <tr>
    <td align="right">{$categories_label}:</td>
    <td>{$categories_input}</td>
  </tr>
{foreach from=$custom_field_inputs item=input}
  <tr>
    <td align="right">{$input.label}</td>
    <td>{$input.input}</td>
  </tr>
{/foreach}
  
  <tr>
    <td></td>
    <td align="left">
      {$form_submit}
      {$form_cancel}
    </td>
  </tr>
</table>
{$form_end}
The Calendar module redirects to the admin after event update, so the last line of Calendar/action.admin_event_update.php has to be changed from

Code: Select all

$this->Redirect($id,'defaultadmin',$returnid,array("module_message"=>$message));
to

Code: Select all

global $CMS_ADMIN_PAGE;

if (isset($CMS_ADMIN_PAGE))
{
    $this->Redirect($id,'defaultadmin',$returnid,array("module_message"=>$message));
}
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

ziad
Forum Members
Forum Members
Posts: 16
Joined: Wed Apr 15, 2009 1:59 pm

Re: MultiUpload module

Post by ziad »

Thank you very much for your assistance!

however, i can browse and upload a file but when i go in to my event i  can only view the name of the file i uploaded, but i cannot click it to open.

any ideas on how to fix this?
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: MultiUpload module

Post by Dee »

ziad wrote: however, i can browse and upload a file but when i go in to my event i  can only view the name of the file i uploaded, but i cannot click it to open.

any ideas on how to fix this?
You'll have to modify the Calendar "Event Template". For a simple link to the file change the code at the end of the template:

Code: Select all

<div class="calendar-fields">
  {foreach from=$event.fields key='fieldname' item='fieldvalue'}
      {$fieldname}: {$fieldvalue}<br/>
  {/foreach}
</div>
to:

Code: Select all

<div class="calendar-fields">
  {foreach from=$event.fields key='fieldname' item='fieldvalue'}
      {$fieldname}: <a href="{$gCms->config.uploads_url}/{$fieldvalue}">{$fieldvalue}</a><br/>
  {/foreach}
</div>
Regards,
D
Last edited by Anonymous on Wed Jul 22, 2009 4:55 pm, edited 1 time in total.
ziad
Forum Members
Forum Members
Posts: 16
Joined: Wed Apr 15, 2009 1:59 pm

Re: MultiUpload module

Post by ziad »

Thanks a lot Dee!
it did help and did the trick.

i just have some cleaning up to do like a LOT of warnings and also when i post an event I am getting this result:

: 0_rabiner.pdf  (this is the name of the folder but not clickable. How do i get rid of this?)
Attachments: 0_rabiner.pdf          (this is where i can view the attachment)
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: MultiUpload module

Post by Dee »

After changing the last bit of Calendar/action.admin_event_update.php
Dee wrote: The Calendar module redirects to the admin after event update, so the last line of Calendar/action.admin_event_update.php has to be changed from

Code: Select all

$this->Redirect($id,'defaultadmin',$returnid,array("module_message"=>$message));
to

Code: Select all

global $CMS_ADMIN_PAGE;

if (isset($CMS_ADMIN_PAGE))
{
    $this->Redirect($id,'defaultadmin',$returnid,array("module_message"=>$message));
}
I only get a message after posting an event from the Frontend:
Event Added

Your event has been successfully added to the calendar.
The calendar module generates a lot of warnings trying (and failing) to create a thumbnail.
The warnings are also generated when an event is added in the Calender module (backend), but are invisible then because of the redirect to the default admin (verified by commenting out the Redirect at the end of action.admin_event_update.php).

To get rid of the messages I simply commented out the lines in Calendar.module.php function HandleUpload (lines 602 and 603) as the thumbnailing doesn't seem to work anyway:

Code: Select all

		    	/*//////////////////////////////////////////////////////////////
			//	Do image resizing
			/////////////////////////////////////////////////////////////*/
//			$this->resize_then_crop($destfilespec,cms_join_path( $destDir, 'thumb_'.$destname),$this->GetPreference('thumb_width',180),$this->GetPreference('thumb_height',180));
//			$this->resize_then_crop($destfilespec,cms_join_path( $destDir, 'large_'.$destname),$this->GetPreference('large_width',500),$this->GetPreference('large_height',500));

Calendar-0.8.2 seems kinda buggy, that's probably the reason it was forked to CGCalendar...

Regards,
D
Post Reply

Return to “Modules/Add-Ons”