diff --git a/private/lib/dao/GenericDao.php b/private/lib/dao/GenericDao.php
index 2dc0973..64c83c7 100644
--- a/private/lib/dao/GenericDao.php
+++ b/private/lib/dao/GenericDao.php
@@ -67,6 +67,9 @@ class GenericDao{
if (array_key_exists("sort",$options)){
$cursor->sort($options["sort"]);
}
+ if (array_key_exists("skip",$options)){
+ $cursor->skip($options["skip"]);
+ }
if (array_key_exists("limit",$options)){
$cursor->limit($options["limit"]);
}
@@ -79,6 +82,38 @@ class GenericDao{
return $rval;
}
+
+ public function count($modelClass, array $filter = array(), array $options = array()){
+ if (!is_null($modelClass)){
+ if (!is_subclass_of($modelClass, "DaoSaveable", true)){
+ throw new CoreException("Invalid return class passed to GenericDao::query ($modelClass)");
+ }
+ }
+
+ $collectionName = $modelClass::getCollectionName();
+ $collection = $this->database->$collectionName;
+
+ $useFilter = $filter;
+
+ if (!array_key_exists("deleted",$useFilter)){
+ $useFilter["deleted"] = false;
+ }
+
+ if (array_key_exists("id",$useFilter)){
+ $useFilter["_id"] = $useFilter["id"];
+ unset($useFilter["id"]);
+ }
+
+ if (array_key_exists("_id",$useFilter) && is_string($useFilter["_id"])){
+ $useFilter["_id"] = new MongoId($useFilter["_id"]);
+ }
+
+
+ $cursor = $collection->find($useFilter);
+
+ return $cursor->count(true);
+ }
+
/**
* Come query ma ritorna il primo o null se non ci sono risultati
* @param string $modelClass
diff --git a/private/lib/dao/models/NotiziaModel.php b/private/lib/dao/models/NotiziaModel.php
index 7117c32..6084a30 100644
--- a/private/lib/dao/models/NotiziaModel.php
+++ b/private/lib/dao/models/NotiziaModel.php
@@ -4,6 +4,18 @@ Author: Riccardo Di Dato
Creation Date: 07/gen/2016
*/
+/**
+ * Campi:
+ * titolo
+ * sottotitolo
+ * testo
+ * about {
+ * author
+ * data
+ * }
+ * @author rik
+ *
+ */
class NotiziaModel extends HasMediaModel{
public static function getCollectionName(){
diff --git a/private/lib/gui/DatatablesHelper.php b/private/lib/gui/DatatablesHelper.php
new file mode 100644
index 0000000..eee9ef0
--- /dev/null
+++ b/private/lib/gui/DatatablesHelper.php
@@ -0,0 +1,94 @@
+draw = $_POST["draw"];
+ $ret->recordsTotal = 0;
+ $ret->recordsFiltered = 0;
+ $ret->data = array();
+
+ if (AdminLoginManager::isLogged()){
+ $admin = AdminLoginManager::getLogged();
+ if ($admin->hasRole($permissionFlagRequired)){
+ $dao = GlobalVariables::get("dao");
+ $filter = array();
+
+ $options = array('limit'=>$_POST["length"], 'skip'=>$_POST["start"]);
+ if (sizeof($_POST["order"])>0){
+ foreach ($_POST["order"] as $details){
+ $key = $_POST["columns"][$details["column"]]["data"];
+ $options["sort"][$key] = strcasecmp($details["dir"], "asc")==0?1:-1;
+ }
+ }
+
+ $models = $dao->query($useModel, $filter, $options);
+
+ if (sizeof($models)>0){
+ foreach ($models as $model){
+ $result = self::getObjectFromFieldsArray($model, $exposedModel);
+
+ $ret->data[] = $result;
+ }
+ }
+ $ret->recordsTotal = $dao->count($useModel);
+ $ret->recordsFiltered = $dao->count($useModel,$filter);
+ }
+ }
+ return $ret;
+ }
+
+ private static function getObjectFromFieldsArray($obj,array $fieldArr){
+ $rval = new stdClass();
+ if (sizeof($fieldArr)>0){
+ foreach ($fieldArr as $key=>$val){
+ if (is_array($val)){
+ $rval->$key = self::getObjectFromFieldsArray($obj->$key, $val);
+ }
+ else {
+ $rval->$key = $obj->$key;
+ }
+ }
+ }
+ return $rval;
+ }
+
+ public static function generateTable($backendPage, array $columns, array $htmlOpts = array()){
+ $tabId = "datatable_".self::$instCount++;
+ $colLabels = "
";
+ $jsCols = array();
+ foreach ($columns as $col){
+ $colLabels.= '| '.$col["label"].' | ';
+
+ $jsCols[]= '{"data":"'.$col["data"].'"}';
+ }
+ $colLabels.= '
';
+
+ echo ''.$colLabels.''.$colLabels.'
';
+
+ echo '';
+
+
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/private/lib/gui/HTMLHelper.php b/private/lib/gui/HTMLHelper.php
index d48d04a..8223f41 100644
--- a/private/lib/gui/HTMLHelper.php
+++ b/private/lib/gui/HTMLHelper.php
@@ -10,7 +10,29 @@ class HTMLHelper {
echo '';
}
-
+ public static function generateModelsTable(array $columnInfo, array $models, array $datatableOpts = array()) {
+ echo '';
+ $colLabels = "";
+ foreach ($columnInfo as $col){
+ $colLabels.= '| '.$col["label"].' | ';
+ }
+ $colLabels.= '
';
+ echo ''.$colLabels.''.$colLabels.'';
+ if (sizeof($models)>0){
+ echo '';
+ foreach ($models as $model){
+ echo '';
+ foreach ($columnInfo as $col){
+ $field = $col["field"];
+ echo '| '.$model->$field.' | ';
+ }
+ echo '
';
+ }
+ echo '';
+ }
+
+ echo '
';
+ }
}
?>
\ No newline at end of file
diff --git a/private/lib/gui/lib.inclusion.php b/private/lib/gui/lib.inclusion.php
index 79ee50d..02f6786 100644
--- a/private/lib/gui/lib.inclusion.php
+++ b/private/lib/gui/lib.inclusion.php
@@ -30,4 +30,5 @@ $systemCatalogManager = new StaticCatalogManager(array());
require_once(dirname(__FILE__)."/html.inclusion.php");
require_once(dirname(__FILE__)."/HTMLHelper.php");
+require_once(dirname(__FILE__)."/DatatablesHelper.php");
?>
\ No newline at end of file
diff --git a/public/admin/notizie.php b/public/admin/notizie.php
new file mode 100644
index 0000000..4dc7a23
--- /dev/null
+++ b/public/admin/notizie.php
@@ -0,0 +1,33 @@
+hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR)){
+ GUIHandler::redirect("admin/index.php");
+}
+
+MenuGenerator::generateMenu();
+
+HTMLHelper::generateAdminHead();
+$columns = array(
+ array("label"=>"Titolo","data"=>"titolo"),
+ array("label"=>"Sottotitolo","data"=>"sottotitolo"),
+ array("label"=>"Autore","data"=>"about.author"),
+ array("label"=>"Data","data"=>"about.data")
+);
+
+?>
+
+
+
\ No newline at end of file
diff --git a/public/admin/roleAdmin.php b/public/admin/roleAdmin.php
index 9b1575b..1cba765 100644
--- a/public/admin/roleAdmin.php
+++ b/public/admin/roleAdmin.php
@@ -11,497 +11,23 @@ GUIHandler::generateHtmlHeaders(array(),true);
if (!AdminLoginManager::isLogged()){
GUIHandler::redirect("admin/login.php");
}
+else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_NORMALADMIN)){
+ GUIHandler::redirect("admin/index.php");
+}
MenuGenerator::generateMenu();
HTMLHelper::generateAdminHead();
+$columns = array(
+ array("label"=>"Titolo","data"=>"titolo"),
+ array("label"=>"Sottotitolo","data"=>"sottotitolo"),
+ array("label"=>"Autore","data"=>"about.author"),
+ array("label"=>"Data","data"=>"about.data")
+);
+
?>
-
-
-
- | Name |
- Position |
- Office |
- Age |
- Start date |
- Salary |
-
-
-
-
- | Name |
- Position |
- Office |
- Age |
- Start date |
- Salary |
-
-
-
-
- | Tiger Nixon |
- System Architect |
- Edinburgh |
- 61 |
- 2011/04/25 |
- $320,800 |
-
-
- | Garrett Winters |
- Accountant |
- Tokyo |
- 63 |
- 2011/07/25 |
- $170,750 |
-
-
- | Ashton Cox |
- Junior Technical Author |
- San Francisco |
- 66 |
- 2009/01/12 |
- $86,000 |
-
-
- | Cedric Kelly |
- Senior Javascript Developer |
- Edinburgh |
- 22 |
- 2012/03/29 |
- $433,060 |
-
-
- | Airi Satou |
- Accountant |
- Tokyo |
- 33 |
- 2008/11/28 |
- $162,700 |
-
-
- | Brielle Williamson |
- Integration Specialist |
- New York |
- 61 |
- 2012/12/02 |
- $372,000 |
-
-
- | Herrod Chandler |
- Sales Assistant |
- San Francisco |
- 59 |
- 2012/08/06 |
- $137,500 |
-
-
- | Rhona Davidson |
- Integration Specialist |
- Tokyo |
- 55 |
- 2010/10/14 |
- $327,900 |
-
-
- | Colleen Hurst |
- Javascript Developer |
- San Francisco |
- 39 |
- 2009/09/15 |
- $205,500 |
-
-
- | Sonya Frost |
- Software Engineer |
- Edinburgh |
- 23 |
- 2008/12/13 |
- $103,600 |
-
-
- | Jena Gaines |
- Office Manager |
- London |
- 30 |
- 2008/12/19 |
- $90,560 |
-
-
- | Quinn Flynn |
- Support Lead |
- Edinburgh |
- 22 |
- 2013/03/03 |
- $342,000 |
-
-
- | Charde Marshall |
- Regional Director |
- San Francisco |
- 36 |
- 2008/10/16 |
- $470,600 |
-
-
- | Haley Kennedy |
- Senior Marketing Designer |
- London |
- 43 |
- 2012/12/18 |
- $313,500 |
-
-
- | Tatyana Fitzpatrick |
- Regional Director |
- London |
- 19 |
- 2010/03/17 |
- $385,750 |
-
-
- | Michael Silva |
- Marketing Designer |
- London |
- 66 |
- 2012/11/27 |
- $198,500 |
-
-
- | Paul Byrd |
- Chief Financial Officer (CFO) |
- New York |
- 64 |
- 2010/06/09 |
- $725,000 |
-
-
- | Gloria Little |
- Systems Administrator |
- New York |
- 59 |
- 2009/04/10 |
- $237,500 |
-
-
- | Bradley Greer |
- Software Engineer |
- London |
- 41 |
- 2012/10/13 |
- $132,000 |
-
-
- | Dai Rios |
- Personnel Lead |
- Edinburgh |
- 35 |
- 2012/09/26 |
- $217,500 |
-
-
- | Jenette Caldwell |
- Development Lead |
- New York |
- 30 |
- 2011/09/03 |
- $345,000 |
-
-
- | Yuri Berry |
- Chief Marketing Officer (CMO) |
- New York |
- 40 |
- 2009/06/25 |
- $675,000 |
-
-
- | Caesar Vance |
- Pre-Sales Support |
- New York |
- 21 |
- 2011/12/12 |
- $106,450 |
-
-
- | Doris Wilder |
- Sales Assistant |
- Sidney |
- 23 |
- 2010/09/20 |
- $85,600 |
-
-
- | Angelica Ramos |
- Chief Executive Officer (CEO) |
- London |
- 47 |
- 2009/10/09 |
- $1,200,000 |
-
-
- | Gavin Joyce |
- Developer |
- Edinburgh |
- 42 |
- 2010/12/22 |
- $92,575 |
-
-
- | Jennifer Chang |
- Regional Director |
- Singapore |
- 28 |
- 2010/11/14 |
- $357,650 |
-
-
- | Brenden Wagner |
- Software Engineer |
- San Francisco |
- 28 |
- 2011/06/07 |
- $206,850 |
-
-
- | Fiona Green |
- Chief Operating Officer (COO) |
- San Francisco |
- 48 |
- 2010/03/11 |
- $850,000 |
-
-
- | Shou Itou |
- Regional Marketing |
- Tokyo |
- 20 |
- 2011/08/14 |
- $163,000 |
-
-
- | Michelle House |
- Integration Specialist |
- Sidney |
- 37 |
- 2011/06/02 |
- $95,400 |
-
-
- | Suki Burks |
- Developer |
- London |
- 53 |
- 2009/10/22 |
- $114,500 |
-
-
- | Prescott Bartlett |
- Technical Author |
- London |
- 27 |
- 2011/05/07 |
- $145,000 |
-
-
- | Gavin Cortez |
- Team Leader |
- San Francisco |
- 22 |
- 2008/10/26 |
- $235,500 |
-
-
- | Martena Mccray |
- Post-Sales support |
- Edinburgh |
- 46 |
- 2011/03/09 |
- $324,050 |
-
-
- | Unity Butler |
- Marketing Designer |
- San Francisco |
- 47 |
- 2009/12/09 |
- $85,675 |
-
-
- | Howard Hatfield |
- Office Manager |
- San Francisco |
- 51 |
- 2008/12/16 |
- $164,500 |
-
-
- | Hope Fuentes |
- Secretary |
- San Francisco |
- 41 |
- 2010/02/12 |
- $109,850 |
-
-
- | Vivian Harrell |
- Financial Controller |
- San Francisco |
- 62 |
- 2009/02/14 |
- $452,500 |
-
-
- | Timothy Mooney |
- Office Manager |
- London |
- 37 |
- 2008/12/11 |
- $136,200 |
-
-
- | Jackson Bradshaw |
- Director |
- New York |
- 65 |
- 2008/09/26 |
- $645,750 |
-
-
- | Olivia Liang |
- Support Engineer |
- Singapore |
- 64 |
- 2011/02/03 |
- $234,500 |
-
-
- | Bruno Nash |
- Software Engineer |
- London |
- 38 |
- 2011/05/03 |
- $163,500 |
-
-
- | Sakura Yamamoto |
- Support Engineer |
- Tokyo |
- 37 |
- 2009/08/19 |
- $139,575 |
-
-
- | Thor Walton |
- Developer |
- New York |
- 61 |
- 2013/08/11 |
- $98,540 |
-
-
- | Finn Camacho |
- Support Engineer |
- San Francisco |
- 47 |
- 2009/07/07 |
- $87,500 |
-
-
- | Serge Baldwin |
- Data Coordinator |
- Singapore |
- 64 |
- 2012/04/09 |
- $138,575 |
-
-
- | Zenaida Frank |
- Software Engineer |
- New York |
- 63 |
- 2010/01/04 |
- $125,250 |
-
-
- | Zorita Serrano |
- Software Engineer |
- San Francisco |
- 56 |
- 2012/06/01 |
- $115,000 |
-
-
- | Jennifer Acosta |
- Junior Javascript Developer |
- Edinburgh |
- 43 |
- 2013/02/01 |
- $75,650 |
-
-
- | Cara Stevens |
- Sales Assistant |
- New York |
- 46 |
- 2011/12/06 |
- $145,600 |
-
-
- | Hermione Butler |
- Regional Director |
- London |
- 47 |
- 2011/03/21 |
- $356,250 |
-
-
- | Lael Greer |
- Systems Administrator |
- London |
- 21 |
- 2009/02/27 |
- $103,500 |
-
-
- | Jonas Alexander |
- Developer |
- San Francisco |
- 30 |
- 2010/07/14 |
- $86,500 |
-
-
- | Shad Decker |
- Regional Director |
- Edinburgh |
- 51 |
- 2008/11/13 |
- $183,000 |
-
-
- | Michael Bruce |
- Javascript Developer |
- Singapore |
- 29 |
- 2011/06/27 |
- $183,000 |
-
-
- | Donna Snider |
- Customer Support |
- New York |
- 27 |
- 2011/01/25 |
- $112,000 |
-
-
-
+
-
\ No newline at end of file
diff --git a/public/admin/tablesBackends/notiziaTableBackend.php b/public/admin/tablesBackends/notiziaTableBackend.php
new file mode 100644
index 0000000..ba3750f
--- /dev/null
+++ b/public/admin/tablesBackends/notiziaTableBackend.php
@@ -0,0 +1,158 @@
+draw = $_POST["draw"];
+
+// $arr = array();
+// $ele = new stdClass();
+// $ele->Sottotitolo = print_r($_POST,true);
+// $ele->Titolo = "asd";
+// $ele->about = new stdClass();
+// $ele->about->autore = "autore";
+// $ele->about->data = "data";
+
+// $arr[] = $ele;
+// for ($i=0; $i<9; $i++){
+// $ele = new stdClass();
+// $ele->Sottotitolo = "asd";
+// $ele->Titolo = "asd";
+// $ele->about = new stdClass();
+// $ele->about->autore = "autore";
+// $ele->about->data = "data";
+// $arr[] = $ele;
+// }
+
+// $ret->recordsTotal = 10;
+// $ret->recordsFiltered = 10;
+// $ret->data = $arr;
+// echo json_encode($ret);
+// die();
+
+// OK
+
+$useModel = "NotiziaModel";
+$permissionFlagRequired = AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR;
+$exposedFields = array(
+ "titolo"=>null,
+ "sottotitolo"=>null,
+ "about"=>null
+);
+
+$ret = DatatablesHelper::getResult($useModel, $permissionFlagRequired, $exposedFields);
+echo json_encode($ret);
+
+// $ret = new stdClass();
+// $ret->draw = $_POST["draw"];
+// $ret->recordsTotal = 0;
+// $ret->recordsFiltered = 0;
+// $ret->data = array();
+
+// if (AdminLoginManager::isLogged()){
+// $admin = AdminLoginManager::getLogged();
+// if ($admin->hasRole($permissionFlagRequired)){
+// $dao = GlobalVariables::get("dao");
+// $filter = array();
+
+// $options = array('limit'=>$_POST["length"], 'skip'=>$_POST["start"]);
+// if (sizeof($_POST["order"])>0){
+// foreach ($_POST["order"] as $details){
+// $key = $_POST["columns"][$details["column"]]["data"];
+// $options["sort"][$key] = strcasecmp($details["dir"], "asc")==0?1:-1;
+// }
+// }
+
+// $models = $dao->query($useModel, $filter, $options);
+
+// if (sizeof($models)>0){
+// foreach ($models as $model){
+// $result = new stdClass();
+// foreach ($exposedFields as $key=>$subfield){
+// if (is_array($subfield)){
+// $result->$key = new stdClass();
+// if (sizeof($subfield)>0){
+// foreach ($subfield as $field){
+// $result->$key->$field = $model->$key->$field;
+// }
+// }
+// }
+// else {
+// $result->$key = $model->$key;
+// }
+// }
+// $result->titolo = $model->titolo;
+// $result->sottotitolo = $model->sottotitolo;
+// $result->about = $model->about;
+
+// $ret->data[] = $result;
+// }
+// }
+// $ret->recordsTotal = $dao->count($useModel);
+// $ret->recordsFiltered = $dao->count($useModel,$filter);
+// }
+// }
+
+// echo json_encode($ret);
+
+
+
+die();
+
+$table = 'datatables_demo';
+
+// Table's primary key
+$primaryKey = 'id';
+
+// Array of database columns which should be read and sent back to DataTables.
+// The `db` parameter represents the column name in the database, while the `dt`
+// parameter represents the DataTables column identifier. In this case object
+// parameter names
+$columns = array(
+ array( 'db' => 'first_name', 'dt' => 'first_name' ),
+ array( 'db' => 'last_name', 'dt' => 'last_name' ),
+ array( 'db' => 'position', 'dt' => 'position' ),
+ array( 'db' => 'office', 'dt' => 'office' ),
+ array(
+ 'db' => 'start_date',
+ 'dt' => 'start_date',
+ 'formatter' => function( $d, $row ) {
+ return date( 'jS M y', strtotime($d));
+ }
+),
+array(
+ 'db' => 'salary',
+ 'dt' => 'salary',
+ 'formatter' => function( $d, $row ) {
+ return '$'.number_format($d);
+ }
+)
+);
+
+// SQL server connection information
+$sql_details = array(
+ 'user' => '',
+ 'pass' => '',
+ 'db' => '',
+ 'host' => ''
+);
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * If you just want to use the basic configuration for DataTables with PHP
+* server-side, there is no need to edit below this line.
+*/
+
+require( 'ssp.class.php' );
+
+echo json_encode(
+ SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns )
+);
+
+
+
+?>
\ No newline at end of file