- Revisión de la pantalla de productos git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@61 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
108 lines
4.4 KiB
PHP
108 lines
4.4 KiB
PHP
<?php
|
|
|
|
class EquipoController extends Controller {
|
|
|
|
/**
|
|
* @return array action filters
|
|
*/
|
|
public function filters() {
|
|
return array(
|
|
'accessControl', // perform access control for CRUD operations
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Specifies the access control rules.
|
|
* This method is used by the 'accessControl' filter.
|
|
* @return array access control rules
|
|
*/
|
|
public function accessRules() {
|
|
return array(
|
|
array('allow',
|
|
'actions' => array('index', 'deleteMember'),
|
|
'users' => array('@'),
|
|
'expression' => 'Yii::app()->user->esCoordinador',
|
|
),
|
|
array('deny', // deny all users
|
|
'users' => array('*'),
|
|
),
|
|
);
|
|
}
|
|
|
|
public function actionIndex() {
|
|
$invitacion = new FormularioInvitarAgente;
|
|
|
|
if (isset($_POST['FormularioInvitarAgente'])) {
|
|
Yii::trace('Dar de alta un nuevo agente', 'application.controllers.EquipoController');
|
|
$invitacion->attributes = $_POST['FormularioInvitarAgente'];
|
|
|
|
if ($invitacion->validate()) {
|
|
$nuevo_usuario = new Usuario('registrar');
|
|
$nuevo_usuario->id_empresa = Yii::app()->user->id_empresa;
|
|
$nuevo_usuario->tipo = Usuario::TIPO_USUARIO_AGENTE;
|
|
$nuevo_usuario->nombre = $invitacion->nombre;
|
|
$nuevo_usuario->email = $invitacion->email;
|
|
$nuevo_usuario->password = $nuevo_usuario->encryptPassword(microtime());
|
|
$nuevo_usuario->estado = Usuario::ESTADO_NOACTIVO;
|
|
$nuevo_usuario->clave_seguridad = $nuevo_usuario->encryptSecureKey(microtime() . $nuevo_usuario->password);
|
|
|
|
if ($nuevo_usuario->save()) {
|
|
EMail::enviarBienvenidaAgente($nuevo_usuario->email, $nuevo_usuario->clave_seguridad);
|
|
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha enviado la invitación a la dirección') . ' ' . $invitacion->email);
|
|
$invitacion = new FormularioInvitarAgente;
|
|
} else {
|
|
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al registrar la invitación'));
|
|
Yii::log(CVarDumper::dumpAsString($nuevo_usuario->attributes), CLogger::LEVEL_ERROR, $this->id);
|
|
}
|
|
} else {
|
|
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al validar la invitación'));
|
|
}
|
|
}
|
|
|
|
$agentes = Usuario::model()->equipo()->findAll();
|
|
|
|
if (count($agentes) >= Yii::app()->user->subscripcion->producto->max_agentes)
|
|
$invitacion = NULL;
|
|
|
|
$this->render('index', array(
|
|
'agentes' => $agentes,
|
|
'invitacion' => $invitacion,
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @brief Elimina a un miembro (agente) del equipo.
|
|
* También envía un email al agente informándole.
|
|
*/
|
|
public function actionDeleteMember($id) {
|
|
$agente = $this->loadModel($id);
|
|
if ($agente) {
|
|
try {
|
|
Yii::trace('Eliminando el agente', 'application.controllers.EquipoController');
|
|
$agente->delete();
|
|
EMail::enviarConfirmacionCancelacion($agente->email);
|
|
Yii::app()->user->setFlash('success', Yii::t('profind', 'Se ha eliminado el agente'));
|
|
} catch (Exception $e) {
|
|
Yii::trace($e->getMessage(), 'application.controllers.UsuarioController');
|
|
Yii::app()->user->setFlash('error', Yii::t('profind', 'Se ha producido un error al eliminar el agente'));
|
|
Yii::app()->user->setFlash('error', CHtml::errorSummary($agente));
|
|
}
|
|
}
|
|
if (!isset($_GET['ajax']))
|
|
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
|
|
}
|
|
|
|
/**
|
|
* Returns the data model based on the primary key given in the GET variable.
|
|
* If the data model is not found, an HTTP exception will be raised.
|
|
* @param integer the ID of the model to be loaded
|
|
*/
|
|
public function loadModel($id) {
|
|
$model = Usuario::model()->equipo()->findByPk($id);
|
|
if ($model === null)
|
|
throw new CHttpException(404, Yii::t('profind', 'La página solicitada no existe.'));
|
|
return $model;
|
|
}
|
|
|
|
}
|