function uploadFile() { $request = Slim::getInstance()->request(); $user = json_decode($request->getBody()); $content = $user->content; $filename = $user->filename ? $user->filename : time(); $piva = trim_string($user->piva); $username = $user->username; $AppModel = new Model(); $Assoc = new AssociazioneModel(); $id_utente = $AppModel->getIdUtente($username); $id_database = $AppModel->getIdDbbyCodice($piva); $id_associazione = $Assoc->getIDAssociazione((int) $id_database, (int) $id_utente); if (!is_null($id_associazione)) { $upload_folder = PATH_BASE . DS . CSV . DS . $piva; if (file_exists($upload_folder)) { if ($content !== NULL) { $res = file_put_contents($upload_folder . '/' . $filename . '.zip', base64_decode($content)); if ($res !== FALSE) { $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "I file sono stati inviati correttamente.", "data" => array("size" => $res))); echo json_encode($status); } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "Errore scrittura dati su filesystem.", "data" => array("size" => $res))); echo json_encode($status); } } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "I file sono vuoti o in formato non riconosciuto.", "data" => array("size" => 0))); echo json_encode($status); } } else { mkdir(PATH_BASE . DS . CSV . DS . $piva, 0777, true); if ($content !== NULL) { $res = file_put_contents($upload_folder . '/' . $filename . '.zip', base64_decode($content)); if ($res !== FALSE) { $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "Nuova cartella creata e i dati sono stati importati con successo.", "data" => array("size" => $res))); echo json_encode($status); } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "Errore scrittura dati su filesystem.", "data" => array("size" => $res))); echo json_encode($status); } } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "I file sono vuoti o in formato non riconosciuto.", "data" => array("size" => 0))); echo json_encode($status); } } } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "L'utente non dispone dei permessi di scrittura. Verificare che le credenziali di accesso e la Partita IVA siano impostate correttamente.", "data" => array("size" => 0))); echo json_encode($status); } }
function formulize($code) { while (true) { $changed = false; $changed |= trim_backslash($code); $changed |= trim_string($code); $changed |= trim_params($code); $changed |= trim_function($code); // $changed |= trim_expression($code); if (!$changed) { break; } } return $code; }
"><?php comment_author(); ?> </a></td> <td><?php comment_author_email_link('email'); ?> </td> <td><?php echo trim_string($comment->comment_content, 50); ?> </td> <td><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP(); ?> " title="<?php comment_author_IP(); ?> "><?php echo $comment->count; ?> </a></td>
function DisplayHtmlContent() { global $config; log_access($this->id, 'html'); echo html_page_header(true, '', 'name'); // Embed first page of OCR text, added 2011-12-07 if ($this->in_bhl) { $pages = bhl_retrieve_reference_pages($this->id); $page_ids = array($pages[0]->PageID); $text = bhl_fetch_text_for_pages($page_ids); $text = str_replace('\\n', '', $text); $text = str_replace('- ', '-', $text); $text = str_replace('- ', '-', $text); echo "\n<!-- First page of OCR text -->\n"; echo '<div style="display:none;">' . "\n"; echo htmlentities($text, ENT_COMPAT, "UTF-8"); echo '</div>' . "\n"; } echo '<div style="float:right;background-color:rgb(230,242,250);padding:6px">' . "\n"; echo '<h2>Identifiers</h2>' . "\n"; echo '<ul class="guid-list">' . "\n"; echo '<li class="permalink">' . '<div itemscope itemtype="http://schema.org/ScholarlyArticle">' . '<a href="' . $config['web_root'] . 'reference/' . $this->id . '" title="Permalink">' . $config['web_root'] . 'reference/' . $this->id . '</a>' . '</div>' . '</li>' . "\n"; if ($this->in_bhl) { echo '<li class="bhl"><a href="http://www.biodiversitylibrary.org/page/' . $this->object->PageID . '" target="_new" title="BHL page" onClick="_gaq.push([\'_trackEvent\', \'Outbound Links\', \'bhl\', \'' . $this->object->PageID . '\', 0]);">' . $this->object->PageID . '</a></li>' . "\n"; } if (isset($this->object->doi)) { echo '<li class="doi"><a href="http://dx.doi.org/' . $this->object->doi . '" target="_new" title="DOI" onClick="_gaq.push([\'_trackEvent\', \'Outbound Links\', \'doi\', \'' . $this->object->doi . '\', 0]);">' . $this->object->doi . '</a></li>' . "\n"; } if (isset($this->object->url)) { echo '<li class="url"><a href="' . $this->object->url . '" target="_new" title="URL">' . trim_string($this->object->url, 30) . '</a></li>' . "\n"; } if (isset($this->object->pdf)) { echo '<li class="pdf"><a href="' . $this->object->pdf . '" target="_new" title="PDF">' . trim_string($this->object->pdf, 30) . '</a></li>' . "\n"; } if (isset($this->object->hdl)) { echo '<li class="handle"><a href="http://hdl.handle.net/' . $this->object->hdl . '" target="_new" title="Handle">' . $this->object->hdl . '</a></li>' . "\n"; } if (isset($this->object->lsid)) { echo '<li class="lsid"><a href="' . $config['web_root'] . $this->object->lsid . '" title="LSID">' . $this->object->lsid . '</a></li>' . "\n"; } if (isset($this->object->pmid)) { echo '<li class="pmid"><a href="http://www.ncbi.nlm.nih.gov/pubmed/' . $this->object->pmid . '" target="_new" title="PMID" >' . $this->object->pmid . '</a></li>' . "\n"; } echo '</ul>' . "\n"; echo '<h2>Export</h2>' . "\n"; echo '<ul class="export-list">' . "\n"; // Mendeley echo '<li class="mendeley"><a href="http://www.mendeley.com/import/?url=' . urlencode($config['web_root'] . 'reference/' . $this->id) . '" title="Add to Mendeley" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'Mendeley\', \'' . $this->id . '\', 0]);">Mendeley</a></li>'; if ($this->in_bhl) { echo '<li class="pdf"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.pdf" title="PDF" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'pdf\', \'' . $this->id . '\', 0]);">PDF</a></li>'; } echo '<li class="xml"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.xml" title="Endnote XML" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'Endnote\', \'' . $this->id . '\', 0]);">Endnote XML</a></li>'; echo '<li class="ris"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.ris" title="RIS" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'RIS\', \'' . $this->id . '\', 0]);">Reference manager</a></li>'; echo '<li class="bibtex"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.bib" title="BibTex" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'bibtex\', \'' . $this->id . '\', 0]);">BibTex</a></li>'; echo '<li class="bibjson"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.bibjson" title="BibJSON" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'bibjson\', \'' . $this->id . '\', 0]);">BibJSON</a></li>'; echo '<li class="wikipedia"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.wikipedia" title="Wikipedia" target="_new" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'Wikipedia\', \'' . $this->id . '\', 0]);">Wikipedia</a></li>'; if ($this->in_bhl) { echo '<li class="text"><a href="' . $config['web_root'] . 'reference/' . $this->id . '.text" title="Text" onClick="_gaq.push([\'_trackEvent\', \'Export\', \'text\', \'' . $this->id . '\', 0]);">Text</a></li>'; } echo '</ul>' . "\n"; echo '</div>' . "\n"; //------------------------------------------------------------------------------------------ echo '<div itemscope itemtype="http://schema.org/ScholarlyArticle">'; echo '<h1>' . '<div itemprop="name">' . $this->GetTitle() . '</div>' . '</h1>' . "\n"; //------------------------------------------------------------------------------------------ // Authors echo '<div>' . "\n"; $count = 0; $num_authors = count($this->object->authors); if ($num_authors > 0) { foreach ($this->object->authors as $author) { echo '<a href="' . $config['web_root'] . 'author/' . $author->id . '">'; echo $author->forename . ' ' . $author->lastname; if (isset($author->suffix)) { echo ' ' . $author->suffix; } echo '</a>'; $count++; if ($count < $num_authors - 1) { echo ', '; } else { if ($count < $num_authors) { echo ' and '; } } } } echo "\n" . '</div>' . "\n"; //------------------------------------------------------------------------------------------ // Metadata and COinS echo '<div>' . "\n"; echo '<div itemprop="description">'; echo '<span class="journal">'; // Various options for linking journal. if (isset($this->object->issn)) { echo '<a href="' . $config['web_root'] . 'issn/' . $this->object->issn . '">'; echo $this->object->secondary_title; echo '</a>'; } elseif (isset($this->object->oclc)) { echo '<a href="' . $config['web_root'] . 'oclc/' . $this->object->oclc . '">'; echo $this->object->secondary_title; echo '</a>'; } else { echo $this->object->secondary_title; } echo '</span>'; echo ' '; if (isset($this->object->series)) { echo ' <span class="volume">(' . $this->object->series . ') </span>'; } echo '<span class="volume">' . $this->object->volume . '</span>'; if (isset($this->object->issue)) { echo '<span class="issue">' . '(' . $this->object->issue . ')' . '</span>'; } echo ':'; echo ' '; echo '<span class="pages">' . $this->object->spage . '</span>'; if (isset($this->object->epage)) { echo '<span class="pages">' . '-' . $this->object->epage . '</span>'; } if (isset($this->object->year)) { echo ' '; echo '<span class="year">' . '(' . $this->object->year . ')' . '</span>'; } echo reference_to_coins($this->object); echo '</div>' . "\n"; echo '</div>' . "\n"; echo '</div>'; // schema //------------------------------------------------------------------------------------------ // When record added and updated echo '<p class="explanation">Reference added '; echo distanceOfTimeInWords(strtotime($this->object->created), time(), true); echo ' ago'; echo '</p>' . "\n"; //------------------------------------------------------------------------------------------ // Social bookmarking // echo '<g:plusone size="tall"></g:plusone>'; echo '<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical" data-via="rdmpage" data-related="biostor_org">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>'; //------------------------------------------------------------------------------------------ // Export options /* echo '<h2>Export</h2>' . "\n"; echo '<div>' . "\n"; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '.xml" title="Endnote XML">Endnote XML</a></span>'; echo ' | '; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '.ris" title="RIS">Reference manager</a></span>'; echo ' | '; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '.bib" title="BibTex">BibTex</a></span>'; if ($this->in_bhl) { echo ' | '; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '.text" title="Text">Text</a></span>'; } echo '</div>' . "\n"; */ //------------------------------------------------------------------------------------------ // Identifiers /* echo '<h2>Identifiers</h2>' . "\n"; echo '<ul>' . "\n"; if ($this->in_bhl) { // BHL reference echo '<li><a href="http://www.biodiversitylibrary.org/page/' . $this->object->PageID . '" target="_new">BHL PageID:' . $this->object->PageID . '</a></li>' . "\n"; } if (isset($this->object->sici)) { echo '<li><a href="' . $config['web_root'] . 'sici/' . $this->object->sici . '">' . $this->object->sici . '</a></li>' . "\n"; } if (isset($this->object->url)) { echo '<li><a href="' . $this->object->url . '" target="_new">' . $this->object->url . '</a></li>' . "\n"; } if (isset($this->object->pdf)) { echo '<li><a href="' . $this->object->pdf . '" target="_new">' . $this->object->pdf . '</a></li>' . "\n"; } if (isset($this->object->doi)) { echo '<li><a href="http://dx.doi.org/' . $this->object->doi . '" target="_new">' . $this->object->doi . '</a></li>' . "\n"; } if (isset($this->object->hdl)) { echo '<li><a href="http://hdl.handle.net/' . $this->object->hdl . '" target="_new">' . $this->object->hdl . '</a></li>' . "\n"; } if (isset($this->object->lsid)) { echo '<li><a href="' . $config['web_root'] . $this->object->lsid . '">' . $this->object->lsid . '</a></li>' . "\n"; } if (isset($this->object->pmid)) { echo '<li><a href="http://www.ncbi.nlm.nih.gov/pubmed/' . $this->object->pmid . '" target="_new">' . $this->object->pmid . '</a></li>' . "\n"; } echo '</ul>' . "\n";*/ //------------------------------------------------------------------------------------------ // Linking /* echo '<div>' . "\n"; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '/backlinks" title="References">Cites (' . num_cites($this->id) . ')</a></span>'; echo ' | '; echo '<span><a href="' . $config['web_root'] . 'reference/' . $this->id . '/forwardlinks" title="Forward links">Cited by (' . num_cited_by($this->id) . ')</a></span>'; echo '</div>' . "\n"; */ //------------------------------------------------------------------------------------------ if ($this->in_bhl) { //-------------------------------------------------------------------------------------- echo '<h2>Viewer</h2>'; echo '<p id="viewer_status"></p>' . "\n"; echo '<table width="100%" >'; echo '<tr valign="top"><td>'; echo bhl_reference_viewer($this->id, $this->page); echo '</td>'; echo '<td>'; echo $this->DisplayEditForm(); echo '</td></tr>'; echo '</table>'; if (0) { //-------------------------------------------------------------------------------------- $tag_cloud = name_tag_cloud($this->taxon_names); if ($tag_cloud != '') { echo '<h2>Taxon name tag cloud</h2>'; echo '<p class="explanation">Taxonomic names extracted from OCR text for document using uBio tools.</p>'; echo $tag_cloud; echo '<h2>Taxonomic classification</h2>'; if ($config['use_gbif']) { echo '<p class="explanation">GBIF classification for taxonomic names in document</p>'; } else { echo '<p class="explanation">Catalogue of Life classification for taxonomic names in document</p>'; } echo '<div id="taxon_names"></div>'; echo '<script type="text/javascript">make_tag_tree();</script>'; } } //-------------------------------------------------------------------------------------- if (count($this->localities) != 0) { echo '<h2>Localities</h2>'; echo '<p class="explanation">Localities extracted from OCR text.</p>'; echo '<div id="map_canvas" style="width: 600px; height: 300px"></div>'; } //-------------------------------------------------------------------------------------- if (count($this->specimens) != 0) { echo '<h2>Specimens</h2>'; echo '<p class="explanation">Specimen codes extracted from OCR text.</p>'; echo '<ul style="-moz-column-width: 13em; -webkit-column-width: 13em; -moz-column-gap: 1em; -webkit-column-gap: 1em;">'; foreach ($this->specimens as $occurrence) { echo '<li'; if (isset($occurrence->occurrenceID)) { //echo $occurrence->occurrenceID; echo ' class="gbif"'; } else { echo ' class="blank"'; } echo '>'; echo '<a href="specimen/' . rawurlencode($occurrence->code) . '">' . $occurrence->code . '</a>'; echo '</li>'; } echo '</ul>'; } } else { echo '<table width="100%" >'; echo '<tr><td valign="top" width="600">'; $have_content = false; // PDF displayed using Google Docs if (!$have_content) { // If we have a PDF display it using Google Docs Viewer http://docs.google.com/viewer if ($this->object->url) { if (preg_match('/\\.pdf$/', $this->object->url)) { echo '<iframe src="http://docs.google.com/viewer?url='; echo urlencode($this->object->url) . '&embedded=true" width="600" height="700" style="border: none;">' . "\n"; echo '</iframe>' . "\n"; $have_content = true; } } } if (!$have_content) { if (isset($this->object->abstract)) { echo '<h3>Abstract</h3>' . "\n"; echo '<div>' . $this->object->abstract . '</div>' . "\n"; $have_content = true; } } if (!$have_content) { echo '<span>[No text or abstract to display]</span>'; } echo '</td>'; echo '<td>'; echo $this->DisplayEditForm(); echo '</td></tr>'; echo '</table>'; } /* //------------------------------------------------------------------------------------------ // Nomenclature (experimental) $acts = acts_in_publication($this->id); if (count($acts) > 0) { echo '<h2>Names published</h2>' . "\n"; echo '<p class="explanation">New names or combinations published in this reference.</p>' . "\n"; echo '<table cellspacing="0" cellpadding="2">' . "\n"; echo '<tr><th>Name</th><th>Identifier</th></tr>' . "\n"; foreach ($acts as $tn) { echo '<tr>'; echo '<td style="border-bottom:1px solid rgb(228,228,228);"><a href="' . $config['web_root'] . 'name/' . urlencode($tn->ToHTML()) . '">' . $tn->ToHTML() . '</td>'; echo '<td style="border-bottom:1px solid rgb(228,228,228);">' . $tn->global_id . '</td>'; echo '</tr>' . "\n"; } echo '</table>' . "\n"; } */ }
function wpars_rating_widget_replace($post_id, $widget_template, $title_chars = 0, $rating_size = 5) { global $wpdb; $out_put = ''; $get_rating_info = wpars_get_rating_info($post_id); $post_title = get_the_title($post_id); if ($title_chars > 0) { $post_title_trim = ucfirst(strtolower(trim_string($post_title, $title_chars))); } else { $post_title_trim = ucfirst(strtolower($post_title)); } $post_url = get_permalink($post_id); $rating_img = wpars_display_rating_img_widget($post_id, $rating_size); $widget_template = stripslashes($widget_template); $widget_template = str_replace("{total_raters}", $get_rating_info['raters'], $widget_template); $widget_template = str_replace("{rate_average}", $get_rating_info['average'], $widget_template); $widget_template = str_replace("{max_rates}", $get_rating_info['max_rates'], $widget_template); $widget_template = str_replace("{rate_percent}", $get_rating_info['percent'], $widget_template); $widget_template = str_replace("{total_scores}", $get_rating_info['scores'], $widget_template); $widget_template = str_replace("{post_title}", $post_title, $widget_template); $widget_template = str_replace("{post_title_trim}", $post_title_trim, $widget_template); $widget_template = str_replace("{post_url}", $post_url, $widget_template); $widget_template = str_replace("{rating_img}", $rating_img, $widget_template); $out_put .= $widget_template; return $out_put; }
function addUserFromCommerce() { $AppModel = new Model(); $Utente = new UtenteModel(); $Uform = new UtenteForm(); $Dbase = new DatabaseModel(); $Dform = new DatabaseForm(); $Assoc = new AssociazioneModel(); $Aform = new AssociazioneForm(); $request = Slim::getInstance()->request(); $user = json_decode($request->getBody()); //Utente $Uform->email = trim_string($user->email); $Uform->id_utente = null; $pwd = Password::randomPassword(); $Uform->passwd = Password::hashPassword($pwd); $Uform->nome = $user->nome; $numdb = (int) $user->num_db; //TODO: Check for empty number of databases $id_utente = $AppModel->getIdUtente($Uform->email); $piva = trim_string($user->piva); $dbprogr = $AppModel->getNumDB($user->email); $INI = $dbprogr; $FIN = $dbprogr + $numdb; /////////////////////////////////////////////////////////////////////////check if fields are not empty/////////////////////////////// if (!empty($user->email) && !empty($user->piva) && !empty($user->num_db)) { try { ///////////////////////////////////////////////////checks if user exist already or no /////////////////////////////////////// if (empty($id_utente)) { $Utente->saveDb($Uform, 1, 1); $testo = "<p>Salve {$user->email},</p>\r\n <p>i tuoi dati di accesso presso <b>" . NAME . ":</b><br><br>\r\n <b>Nome utente</b>: {$user->email}<br>\r\n <b>Password:</b> {$pwd}</p>\r\n <p>Una volta effettuato l'accesso ti verrà richiesto di cambiare la password tramite l'apposita funzionalità</p>\r\n <p>Adesso puoi effettuare il login al seguente indirizzo: <a href=\"" . URL . "index.php?section=login\">" . URL . "index.php?section=login</a></p>"; Mailer::sendMail($user->email, NAME, EMAIL, false, NAME . ' - Utente e password', $testo); //////////////////////////////////////////////////////////////creates number of databases rquested///////////////////////////////////////////////// $Dform->alias = (string) $user->ragsoc; $dbnames = createDBName($INI, $FIN, $piva); foreach ($dbnames as $key => $value) { $id_database = $AppModel->getIdDb($value); if (empty($id_database)) { $Dform->nome = $value; $Dform->codice = explode("_", $value)[1]; if (!$Dbase->esisteDatabase($Dform->nome)) { $Dbase->saveDb($Dform); if (!file_exists(PATH_BASE . DS . CSV . DS . $Dform->codice) && !is_dir(PATH_BASE . DS . CSV . DS . $Dform->codice)) { mkdir(PATH_BASE . DS . CSV . DS . $Dform->codice, 0777, true); } } } $Aform->id_utente = $AppModel->getIdUtente($user->email); $Aform->id_database = $AppModel->getIdDb($Dform->nome); // use name inserted into db ...not something else $Aform->id_associazione = $Assoc->getIDAssociazione($Aform->id_database, $Aform->id_utente); $Aform->data_scadenza = (string) $user->data_scadenza; if (!$Assoc->controllaUnicita($Aform->id_utente, $Aform->id_database, $Aform->id_associazione)) { $Assoc->saveDb($Aform, 1, 1); } // Check if flight is set, enable menu and impose other conditions. if ($user->tipo_gest == '1') { $Dbase->setAuth($AppModel->getIdDb($Dform->nome), 3, 1); $Dbase->ImpostazioneFlight($Dform->nome); } } //check for errors $AppModel->updateNumDB($Uform->email, $numdb); // TODO: Use error checks to send different jsons that is 1 .error in utente, 2. error in database 3.associazione $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "Richiesta eseguita con successo. E stato creato un utente, un database e un abbinamento/associazione.", "data" => array())); echo json_encode($status); } else { // if user doesn't exist // 3. send email //2. create db, //create assocciazione with all $Dform->alias = (string) $user->ragsoc; $dbnames = createDBName($INI, $FIN, $piva); foreach ($dbnames as $key => $value) { $id_database = $AppModel->getIdDb($value); if (empty($id_database)) { $Dform->nome = $value; $Dform->codice = explode("_", $value)[1]; if (!$Dbase->esisteDatabase($Dform->nome)) { $Dbase->saveDb($Dform); if (!file_exists(PATH_BASE . DS . CSV . DS . $Dform->codice) && !is_dir(PATH_BASE . DS . CSV . DS . $Dform->codice)) { mkdir(PATH_BASE . DS . CSV . DS . $Dform->codice, 0777, true); } } // else check for errors } //$checkdbname = $Dbase->getDatabase($id_database); // check if database exist already // if so try create associasion //else create db and create association $Aform->id_utente = $AppModel->getIdUtente($user->email); $Aform->id_database = $AppModel->getIdDb($Dform->nome); // use name inserted into db ...not something else $Aform->id_associazione = $Assoc->getIDAssociazione($Aform->id_database, $Aform->id_utente); $Aform->data_scadenza = (string) $user->data_scadenza; if (!$Assoc->controllaUnicita($Aform->id_utente, $Aform->id_database, $Aform->id_associazione)) { $Assoc->saveDb($Aform, 1, 1); } // user alreadey exist send check if database exist and check if associzoine exist then send email $testo = "<p>Salve {$user->email},</p>\r\n <p>La sua richiesta è stata accettata. Abbiamo abbinato una nuova basi di dati a questo utente.</p>\r\n <p>i tuoi dati di accesso presso <b>" . NAME . ":</b><br>\r\n <p>Si potrebbe usare le tue credenziali già esistente per accedere.</p>\r\n <p></p>\r\n <p>Adesso puoi effettuare il login al seguente indirizzo: <a href=\"" . URL . "index.php?section=login\">" . URL . "index.php?section=login</a></p>"; Mailer::sendMail($user->email, NAME, EMAIL, false, NAME . ' - Utente e password', $testo); // Check if flight is set, enable menu and impose other conditions. if ($user->tipo_gest == '1') { $Dbase->setAuth($AppModel->getIdDb($Dform->nome), 3, 1); $Dbase->ImpostazioneFlight($Dform->nome); } } // for each $AppModel->updateNumDB($Uform->email, $numdb); // TODO: Use error checks to send different jsons that is 1 .error in utente, 2. error in database 3.associazione $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "Richiesta eseguita con successo.E stato creato un database e un abbinamento/associazione. ", "data" => array())); echo json_encode($status); } // else } catch (Exception $e) { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "Iscrizione negato, email/utente già esistente!", "errmsg" => $e->getMessage(), "data" => null)); echo json_encode($status); } } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "I campi email, numero di database e partita IVA non possono essere vuoti", "data" => null)); echo json_encode($status); } }
/** * Write a wrapper function that * 1. Adds users * 2. Adds database * 3. Creates association between users and database using existing models * Added more checks 14/09/2015 . Must be rewritten if there is time. */ function addUser() { $request = Slim::getInstance()->request(); $user = json_decode($request->getBody()); $AppModel = new Model(); $Utente = new UtenteModel(); $Uform = new UtenteForm(); $Dbase = new DatabaseModel(); $Dform = new DatabaseForm(); $Assoc = new AssociazioneModel(); $Aform = new AssociazioneForm(); //Utente $Uform->email = trim_string($user->email); $Uform->id_utente = null; $pwd = Password::randomPassword(); $Uform->passwd = Password::hashPassword($pwd); //Database $piva = (string) trim_string($user->piva); $Dform->nome = INIDB_WKI . "{$piva}"; $Dform->alias = !empty($user->ragsoc) ? $user->ragsoc : $user->piva; $Dform->codice = $user->piva; //$Dform->id_database = $AppModel->getIdDb($Dform->nome); $Dform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); $id_utente = $AppModel->getIdUtente($Uform->email); if (!empty($user->email) && !empty($user->piva)) { try { if (empty($id_utente)) { ///////////////////////////// User doesn't exist, save user and send and email with password////////////////////////////////////////////////// if ($Utente->saveDb($Uform, 1, 1)) { $testo = "<p>Salve {$user->email},</p>\r\n <p>i tuoi dati di accesso presso <b>" . NAME . ":</b><br><br>\r\n <b>Nome utente</b>: {$user->email}<br>\r\n <b>Password:</b> {$pwd}</p>\r\n <p>Una volta effettuato l'accesso ti verrà richiesto di cambiare la password tramite l'apposita funzionalità</p>\r\n <p>Adesso puoi effettuare il login al seguente indirizzo: <a href=\"" . URL . "index.php?section=login\">" . URL . "index.php?section=login</a></p>"; Mailer::sendMail($user->email, NAME, EMAIL, false, NAME . ' - Utente e password', $testo); } ///////////////////////////// If database exist already, then create association of user and database and date of expiry////////////////////////// if (!empty($Dform->id_database)) { $Aform->id_utente = $AppModel->getIdUtente($user->email); $Aform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); $Aform->data_scadenza = (string) $user->data_scadenza; $Assoc->saveDb($Aform, 1, 1); } else { //////////////////////////// If database does not exist , create datbase and associate it with the user /////////////////////////////////////////// $Dbase->saveDb($Dform); if (!file_exists(PATH_BASE . DS . CSV . DS . $Dform->codice) && !is_dir(PATH_BASE . DS . CSV . DS . $Dform->codice)) { mkdir(PATH_BASE . DS . CSV . DS . $Dform->codice, 0777, true); } $Aform->id_utente = $AppModel->getIdUtente($user->email); $Aform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); $Aform->data_scadenza = (string) $user->data_scadenza; $Assoc->saveDb($Aform, 1, 1); } ////////////////////////// If request is for complete application(f-light), launch this procedure to modify application //////////////////////////////////// if ($user->tipo_gest == '1') { $Dbase->setAuth($AppModel->getIdDbbyCodice($Dform->codice), 3, 1); $Dbase->ImpostazioneFlight($Dform->nome); // maintain name as in name of Database } //////////////////////// If all this is done we are sure that a user, database and their association has been succefully done so throw out json /////////// $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "E stato creato un utente, database e un abbinamento/associazione.", "data" => array())); echo json_encode($status); } else { //////////////////////// We arrived here because user id was found, so we send a message to the user saying we added a database/company to them and they can use old password////// $testo = "<p>Salve {$user->email},</p>\r\n <p>La sua richiesta è stata accettata. Abbiamo abbinato una nuova basi di dati a questo utente.</p>\r\n <p>i tuoi dati di accesso presso <b>" . NAME . ":</b><br>\r\n <p>Si potrebbe usare le tue credenziali già esistente per accedere.</p>\r\n <p></p>\r\n <p>Adesso puoi effettuare il login al seguente indirizzo: <a href=\"" . URL . "index.php?section=login\">" . URL . "index.php?section=login</a></p>"; $Aform->id_utente = $AppModel->getIdUtente($user->email); $Aform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); $Aform->data_scadenza = (string) $user->data_scadenza; $Dform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); ///////////////////////// If a database already exist, we send and email and create and create and association with the user /////////////////////////////////////////////////// if (!empty($Dform->id_database)) { Mailer::sendMail($user->email, NAME, EMAIL, false, NAME . ' - Utente e password', $testo); if (!$Assoc->controllaUnicita($Aform->id_utente, $Aform->id_database, $Aform->id_associazione)) { $Assoc->saveDb($Aform, 1, 1); $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "Un abbinamento/associazione è stato creato.", "data" => array())); echo json_encode($status); } else { $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "Operazione eseguito con succeso, esiste già un associazione", "data" => array())); echo json_encode($status); } ///////////////////////////// If there is no database, then we create database , send email and create folder and association//////////// } else { $Dform->id_database = $AppModel->getIdDbbyCodice($Dform->codice); $Dbase->saveDb($Dform); Mailer::sendMail($user->email, NAME, EMAIL, false, NAME . ' - Utente e password', $testo); if (!file_exists(PATH_BASE . DS . CSV . DS . $Dform->codice) && !is_dir(PATH_BASE . DS . CSV . DS . $Dform->codice)) { mkdir(PATH_BASE . DS . CSV . DS . $Dform->codice, 0777, true); } $Assoc->saveDb($Aform, 1, 1); $status = array("statuscode" => 200, "response" => array("success" => true, "msg" => "E stato creato un database e un abbinamento/associazione. ", "data" => array($Dform->id_database))); echo json_encode($status); } } } catch (Exception $e) { // TODO: What to return $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "Errori nel inserimento su database o nella creazione della cartella !", "errmsg" => $e->getMessage(), "data" => null)); echo json_encode($status); } } else { $status = array("statuscode" => 200, "response" => array("success" => false, "msg" => "I campi email e partita IVA non possono essere vuoti", "data" => null)); echo json_encode($status); } }