raspisms/controllers/publics/Call.php

96 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2021-03-24 00:22:17 +01:00
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\publics;
/**
* Page des calls.
*/
class Call extends \descartes\Controller
{
private $internal_call;
/**
* Cette fonction est appelée avant toute les autres :
* Elle vérifie que l'utilisateur est bien connecté.
*
* @return void;
*/
public function __construct()
{
$bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
$this->internal_call = new \controllers\internals\Call($bdd);
\controllers\internals\Tool::verifyconnect();
}
/**
2021-06-17 00:51:33 +02:00
* Page for showing calls list.
2021-03-24 00:22:17 +01:00
*/
public function list()
{
$this->render('call/list');
}
/**
* Return calls list as json.
*/
public function list_json()
{
$entities = $this->internal_call->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
switch ($entity['direction'])
{
2021-06-17 00:51:33 +02:00
case \models\Call::DIRECTION_INBOUND:
2021-03-24 00:22:17 +01:00
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
2021-06-17 00:51:33 +02:00
2021-03-24 00:22:17 +01:00
break;
2021-06-17 00:51:33 +02:00
case \models\Call::DIRECTION_OUTBOUND:
2021-03-24 00:22:17 +01:00
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
2021-06-17 00:51:33 +02:00
2021-03-24 00:22:17 +01:00
break;
}
}
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
2021-06-17 00:51:33 +02:00
* Delete a list of calls.
2021-03-24 00:22:17 +01:00
*
* @param array int $_GET['ids'] : Ids of calls to delete
2021-06-17 00:51:33 +02:00
* @param string $csrf : csrf token
2021-03-24 00:22:17 +01:00
*
* @return boolean;
*/
public function delete(string $csrf)
{
if (!$this->verify_csrf($csrf))
{
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Call', 'list'));
}
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
$this->internal_call->delete_for_user($_SESSION['user']['id'], $id);
}
return $this->redirect(\descartes\Router::url('Call', 'list'));
}
}