Author: ftoledo Date: 2009-05-18 15:18:04 -0300 (Mon, 18 May 2009) New Revision: 6188 Added: prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/components.class.php prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_verfoto.php prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/addfotoSuccess.php prosistem/alba/trunk/alba/web/images/medium/ajax_loading.gif Modified: prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/actions.class.php prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_foto.php prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/editSuccess.php prosistem/alba/trunk/alba/lib/filter/base/BaseUsuarioFormFilter.class.php Log: upload foto de alumno Modified: prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/actions.class.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/actions.class.php 2009-05-16 23:31:35 UTC (rev 6187) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/actions.class.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -154,7 +154,7 @@ //Actualizo el nro siguiente. $nrosiguiente = $this->alumno->getLegajoNumero() +1; $estable->setLegajoSiguiente($nrosiguiente); - $estable->Save(); + $estable->Save(); $this->getUser()->setFlash('notice', 'Your modifications have been saved'); @@ -175,14 +175,22 @@ public function executeAddfoto(sfWebRequest $request) { - $alumno = AlumnoPeer::retrieveByPk($request->getParameter('id')); - $this->forward404Unless($alumno); - if ($alumno->getLegajoPrefijo() != '' && $alumno->getLegajoNumero() != '') { - $this->getRequest()->moveFile('archivo', sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$alumno->getLegajo(),'.png'); - return $this->renderPartial('foto', array('alumno'=>$alumno)); + $this->alumno = AlumnoPeer::retrieveByPk($request->getParameter('id')); + $this->forward404Unless($this->alumno); + if ($this->alumno->getLegajoPrefijo() != '' && $this->alumno->getLegajoNumero() != '') { + try { + $this->getRequest()->moveFile('archivo', sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$this->alumno->getLegajo(). '.png'); + $this->result = 1; + } + catch (Exception $e) { + $this->result_msg = $e->getMessage(); + $this->result = 0; + } } else { - return $this->renderText('El alumno no tiene un legajo valido!'); + // legajo invalido + $this->result_msg = 'El alumno posee un legajo inválido!'; + $this->result = 0; } } Added: prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/components.class.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/components.class.php (rev 0) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/actions/components.class.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -0,0 +1,22 @@ +<?php +/** + * Componente para la foto del alumno + * + * @author Fernando Toledo <[email protected]> + * @version SVN: $Id$ + */ + +class alumnoComponents extends sfComponents +{ + public function executeVerfoto() + { + $this->foto = 'nofoto.png'; + $archivo_foto = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir_name').DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$this->alumno->getLegajo(); + if (file_exists($archivo_foto . '.png')) { + $this->foto = '..'.DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir_name').DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$this->alumno->getLegajo(); + } + + } + +} +?> \ No newline at end of file Modified: prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_foto.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_foto.php 2009-05-16 23:31:35 UTC (rev 6187) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_foto.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -1,41 +0,0 @@ -<?php use_helper('Javascript')?> -<?php - $foto = 'nofoto.png'; - $archivo_foto = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$alumno->getLegajo(); - if (file_exists($archivo_foto . '.png')) { - $foto = '..'.DIRECTORY_SEPARATOR.'alumnos'.DIRECTORY_SEPARATOR.$alumno->getLegajo(); - } -?> -<div id="foto"> -<table> -<tr> -<td> - <?php echo image_tag($foto, array( - 'width' =>150, - 'class'=>'ajax_link', - 'onClick'=> "Element.show('form_upload')", - 'alt'=>'Foto del alumno / Click para cambiarla', - 'title' => 'Click para cambiarla!', - ))?> -</td> -<td> - <div id="indicator" style="display: none;position: relative"></div> - <div id="form_upload" style="display:none; border:1px solid #ccccff; padding: 10px; width:300px"> - <p>Seleccione una imágen</p> - <?php echo form_remote_tag(array( - 'update' => 'foto', - 'url' => 'alumno/addfoto', - 'loading' => "Element.show('indicator')", - 'complete' => "Element.hide('indicator')", - 'multipart'=>true, - ))?> - <?php echo input_hidden_tag('id', $alumno->getId())?> - <?php echo input_file_tag('archivo');?> - <br/> - <?php echo submit_tag('Aceptar')?> - </form> - </div> -</td> -</tr> -</table> -</div> Added: prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_verfoto.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_verfoto.php (rev 0) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/_verfoto.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -0,0 +1,64 @@ +<?php use_helper('Javascript')?> + +<script language="Javascript"> + function startUpload(){ + + document.getElementById('foto').innerHTML = + '<?php echo image_tag('medium/ajax_loading.gif', array('title'=>'Cargando...','alt'=>'Cargando', 'width'=>150))?>'; + return true; + } + + function stopUpload(success, msg){ + var result = ''; + if (success == 1){ + document.getElementById('foto').innerHTML = msg; + document.getElementById('form_upload').style.visibility = 'hidden'; + } + else { + document.getElementById('result').innerHTML = + '<span class="error">Error al subir el archivo!<\/span><br/>' +msg+ '<br/>'; + document.getElementById('foto').innerHTML=''; + } + return true; + } +</script> +<style> + form .ajax_upload{ + text-align:center; + width:390px; + margin:0px; + padding:5px; + background-color:#fff; + border:1px solid #ccc; + } +</style> +<?php if (sfConfig::get('sf_debug')):?> + <p>Ajax Upload debug!</p> + <iframe id ="framefoto" name="framefoto" src="#" style="width:600px;border:1px solid #ff0000;"></iframe> +<?php else:?> + <iframe id ="framefoto" name="framefoto" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe> +<?php endif;?> +<div id="foto" style=""> + <?php echo image_tag($foto, array( + 'width' =>150, + 'class'=>'ajax_link', + 'onClick'=> "Element.show('form_upload')", + 'alt'=>'Foto del alumno / Click para cambiarla', + 'title' => 'Click para cambiarla!', + ))?> +</div> +<div id="result"></div> +<div id="form_upload" style="display:none; border:1px solid #ccccff; padding: 10px; width:300px"> + <p>Seleccione una imágen</p> + <?php echo form_tag('alumno/addfoto',array( + 'multipart' => true, + 'target' => 'framefoto', + 'onSubmit' => 'startUpload()', + 'class' =>'ajax_upload', + ))?> + <?php echo input_hidden_tag('id', $alumno->getId())?> + <?php echo input_file_tag('archivo');?> + <br/> + <?php echo submit_tag('Aceptar')?> + </form> +</div> Added: prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/addfotoSuccess.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/addfotoSuccess.php (rev 0) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/addfotoSuccess.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -0,0 +1,29 @@ +<?php +/* + * Created on 15/05/2009 + * + * To change the template for this generated file go to + * Window - Preferences - PHPeclipse - PHP - Code Templates + */ +?> +<?php +if ($result) { + $result_msg = addslashes(image_tag('../uploads/alumnos/' .$alumno->getLegajo(), array( + 'width' =>150, + 'class'=>'ajax_link', + 'onClick'=> "Element.show('form_upload')", + 'alt'=>'Foto del alumno / Click para cambiarla:' . $alumno->getLegajo(), + 'title' => 'Click para cambiarla!', + ))); + + $result_msg = image_tag('../uploads/alumnos/' .$alumno->getLegajo() .'.png', array( + 'width' =>150, + )); +} +?> +<div id="script-stop"> +<script language="javascript" type="text/javascript"> + window.top.window.stopUpload(<?php echo $result?>, '<?php echo $result_msg?>'); +</script> +</div> + Modified: prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/editSuccess.php =================================================================== --- prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/editSuccess.php 2009-05-16 23:31:35 UTC (rev 6187) +++ prosistem/alba/trunk/alba/apps/principal/modules/alumno/templates/editSuccess.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -24,21 +24,19 @@ <div id="sf_admin_header"> <?php include_partial('alumno/edit_header', array('alumno' => $alumno)) ?> </div> - <?php if ($sf_request->getParameter('action') == 'edit'): ?> - <?php include_partial('alumno/foto', array('alumno'=>$alumno))?> - <?php endif;?> <?php if ($sf_user->hasFlash('notice')): ?> <div class="save-ok"> <h2><?php echo __($sf_user->getFlash('notice')) ?></h2> </div> <?php endif; ?> - + <?php if ($sf_request->getParameter('action') == 'edit'): ?> + <?php include_component('alumno', 'verfoto', array('alumno'=>$alumno))?> + <?php endif;?> <?php echo form_tag('alumno/edit', 'id=sf_admin_edit_form name=sf_admin_edit_form multipart=true') ?> <?php echo object_input_hidden_tag($alumno, 'getId') ?> <fieldset id="sf_fieldset_informacion_general" class=""> <h2><?php echo __('Información general') ?></h2> - <!-- Legajo --> <div class="form-row"> <?php echo label_for('alumno[legajo_prefijo]', __('Legajo:'), 'class="required" ') ?> @@ -52,7 +50,7 @@ <?php echo form_error('alumno{legajo_numero}', array('class' => 'form-error-msg')) ?> <?php endif; ?> - <?php echo input_tag('alumno[legajo_prefijo]', (isset($prefijo)?$prefijo:"")) ?> + <?php echo input_tag('alumno[legajo_prefijo]', (isset($prefijo)?$prefijo:"")) ?> <?php echo input_tag('alumno[legajo_numero]', (isset($nrolegajo)?$nrolegajo:"")) ?> </div> </div> Modified: prosistem/alba/trunk/alba/lib/filter/base/BaseUsuarioFormFilter.class.php =================================================================== --- prosistem/alba/trunk/alba/lib/filter/base/BaseUsuarioFormFilter.class.php 2009-05-16 23:31:35 UTC (rev 6187) +++ prosistem/alba/trunk/alba/lib/filter/base/BaseUsuarioFormFilter.class.php 2009-05-18 18:18:04 UTC (rev 6188) @@ -26,8 +26,8 @@ 'email' => new sfWidgetFormFilterInput(), 'fk_establecimiento_id' => new sfWidgetFormPropelChoice(array('model' => 'Establecimiento', 'add_empty' => true)), 'borrado' => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))), + 'usuario_permiso_list' => new sfWidgetFormPropelChoice(array('model' => 'Permiso', 'add_empty' => true)), 'usuario_rol_list' => new sfWidgetFormPropelChoice(array('model' => 'Rol', 'add_empty' => true)), - 'usuario_permiso_list' => new sfWidgetFormPropelChoice(array('model' => 'Permiso', 'add_empty' => true)), )); $this->setValidators(array( @@ -42,8 +42,8 @@ 'email' => new sfValidatorPass(array('required' => false)), 'fk_establecimiento_id' => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Establecimiento', 'column' => 'id')), 'borrado' => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))), + 'usuario_permiso_list' => new sfValidatorPropelChoice(array('model' => 'Permiso', 'required' => false)), 'usuario_rol_list' => new sfValidatorPropelChoice(array('model' => 'Rol', 'required' => false)), - 'usuario_permiso_list' => new sfValidatorPropelChoice(array('model' => 'Permiso', 'required' => false)), )); $this->widgetSchema->setNameFormat('usuario_filters[%s]'); @@ -53,7 +53,7 @@ parent::setup(); } - public function addUsuarioRolListColumnCriteria(Criteria $criteria, $field, $values) + public function addUsuarioPermisoListColumnCriteria(Criteria $criteria, $field, $values) { if (!is_array($values)) { @@ -65,20 +65,20 @@ return; } - $criteria->addJoin(UsuarioRolPeer::FK_USUARIO_ID, UsuarioPeer::ID); + $criteria->addJoin(UsuarioPermisoPeer::FK_USUARIO_ID, UsuarioPeer::ID); $value = array_pop($values); - $criterion = $criteria->getNewCriterion(UsuarioRolPeer::FK_ROL_ID, $value); + $criterion = $criteria->getNewCriterion(UsuarioPermisoPeer::FK_PERMISO_ID, $value); foreach ($values as $value) { - $criterion->addOr($criteria->getNewCriterion(UsuarioRolPeer::FK_ROL_ID, $value)); + $criterion->addOr($criteria->getNewCriterion(UsuarioPermisoPeer::FK_PERMISO_ID, $value)); } $criteria->add($criterion); } - public function addUsuarioPermisoListColumnCriteria(Criteria $criteria, $field, $values) + public function addUsuarioRolListColumnCriteria(Criteria $criteria, $field, $values) { if (!is_array($values)) { @@ -90,14 +90,14 @@ return; } - $criteria->addJoin(UsuarioPermisoPeer::FK_USUARIO_ID, UsuarioPeer::ID); + $criteria->addJoin(UsuarioRolPeer::FK_USUARIO_ID, UsuarioPeer::ID); $value = array_pop($values); - $criterion = $criteria->getNewCriterion(UsuarioPermisoPeer::FK_PERMISO_ID, $value); + $criterion = $criteria->getNewCriterion(UsuarioRolPeer::FK_ROL_ID, $value); foreach ($values as $value) { - $criterion->addOr($criteria->getNewCriterion(UsuarioPermisoPeer::FK_PERMISO_ID, $value)); + $criterion->addOr($criteria->getNewCriterion(UsuarioRolPeer::FK_ROL_ID, $value)); } $criteria->add($criterion); @@ -123,8 +123,8 @@ 'email' => 'Text', 'fk_establecimiento_id' => 'ForeignKey', 'borrado' => 'Boolean', + 'usuario_permiso_list' => 'ManyKey', 'usuario_rol_list' => 'ManyKey', - 'usuario_permiso_list' => 'ManyKey', ); } } Added: prosistem/alba/trunk/alba/web/images/medium/ajax_loading.gif =================================================================== (Binary files differ) Property changes on: prosistem/alba/trunk/alba/web/images/medium/ajax_loading.gif ___________________________________________________________________ Added: svn:mime-type + application/octet-stream