Location: PHPKode > projects > QuickTicket > quickticket/qti_adm_section_img.php
<?php

/**
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20101222
*/

session_start();
require_once('bin/qti_init.php');
include(Translate('qti_adm.php'));
include(Translate('qti_reg.php'));

if ( $oVIP->role!='A' ) die(Error(13));

// INITIALISE

$s = -1; QThttpvar('s','int'); if ( $s<0 ) die('Missing parameters');

$oSEC = new cSection($s);

$intWidth = 50;
$intSize = 10;

$oVIP->selfurl = 'qti_adm_section_img.php';
$oVIP->selfname = '<span class="upper">'.$L['Adm_content'].'</span><br />'.$L['Section_upd'];
$oVIP->exiturl = 'qti_adm_section.php?tt=1&amp;s='.$s;

// --------
// SUBMITTED FOR DELETE
// --------

if ( isset($_POST['del']) )
{
  unlink('upload/section/'.$oSEC->d_logo);
  $oSEC->options = QTimplode(QTarradd(QTexplode($oSEC->options),'logo','0'));
  $oSEC->WriteOptions();

  $oVIP->selfname = $L['Section_upd'];
  $oVIP->EndMessage(NULL,$L['S_delete'],$_SESSION[QT]['skin_dir'],2);
}

// --------
// SUBMITTED FOR UPLOAD
// --------

if ( isset($_POST['ok']) )
{
  // Check uploaded document

  $error = InvalidUpload($_FILES['title'],'gif,jpg,jpeg,png','',0,50,50);

  // Upload

  if ( empty($error) )
  {
    $strExt = strtolower(substr(strrchr($_FILES['title']['name'],'.'),1));
    if ( !copy($_FILES['title']['tmp_name'],'upload/section/'.$s.'.'.$strExt) ) $error='Problem to copy the uploaded file in the application directory (upload/section/).';
    unlink($_FILES['title']['tmp_name']);
  }
  
  // Update section
  
  if ( empty($error) )
  {
    $oSEC->options = QTimplode(QTarradd(QTexplode($oSEC->options),'logo',$s.'.'.$strExt));
    $oSEC->WriteOptions();
    $oVIP->selfname = $L['Section_upd'];
    $oVIP->EndMessage(NULL,$L['S_update'],$_SESSION[QT]['skin_dir'],2);
  }
  else
  {
    $oVIP->EndMessage(NULL,$error,$_SESSION[QT]['skin_dir'],0);
  }
}

// --------
// HTML START
// --------

$strHeadScript = '
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
  if (theForm.title.value.length==0) { alert("'.$L['Missing'].': File"); return false; }
  return null;
}
-->
</script>
';
include('qti_adm_p_header.php');

$str='';
if ( file_exists('upload/section/'.$s.'.gif') ) $str = 'upload/section/'.$s.'.gif';
if ( file_exists('upload/section/'.$s.'.jpg') ) $str = 'upload/section/'.$s.'.jpg';
if ( file_exists('upload/section/'.$s.'.png') ) $str = 'upload/section/'.$s.'.png';
if ( file_exists('upload/section/'.$s.'.jpeg') ) $str = 'upload/section/'.$s.'.jpeg';

echo '<table class="hidden" cellspacing="0">
<tr class="hidden">
<td class="hidden" style="width:175px;"><br />',AsImgBox(AsImg($str),'picbox'),'</td>
<td class="hidden" style="width:360px;">
';

$oHtml->Msgbox($L['Add'].' logo');

echo '<form method="post" action="',$oVIP->selfurl,'" enctype="multipart/form-data" onsubmit="return ValidateForm(this);">',N;

if ( !empty($error) ) echo '<span class="error">',$error,'</span>',N;
echo '<p style="text-align:right">32x32 pixels (max ',$intWidth,'x',$intWidth,' pixels)<br /><br />
<input type="hidden" name="max_file_size" value="',($intSize*1024),'" />
<input type="hidden" name="s" value="',$s,'" />
<input type="file" id="title" name="title" size="32" />
<input type="submit" name="ok" value="',$L['Save'],'" /></p>
</form>
';

$oHtml->Msgbox();

if ( !empty($str) )
{
  $oHtml->Msgbox($L['Remove'].' logo');
  echo '<form method="post" action="',$oVIP->selfurl,'">
  <p style="text-align:right">
  <input type="hidden" name="s" value="',$s,'" />
  <input type="submit" name="del" value="',$L['Delete'],'" /></p>
  </form>
  ';
  $oHtml->Msgbox();
}

echo '
</td>
</tr>
</table>
<p><a href="',$oVIP->exiturl,'">&laquo; ',$oVIP->exitname,'</a></p>
';

// HTML END

include('qti_adm_p_footer.php');

?>
Return current item: QuickTicket