Example #1
0
     }
 }
 if (isset($query2)) {
     mysql_query($query2) or die(mysql_error());
 }
 if ($_GET['cosa'] != 'foto_usato') {
     $query .= ')';
     $value .= ')';
     mysql_query($query . $value) or die(mysql_error());
     $id_modello = mysql_insert_id();
 }
 $i = $id_modello;
 foreach ($foto as $f) {
     $descrizione = $id_modello . $f['nome'];
     if ($_FILES[$f['nome']]['tmp_name'] != '' && !isset($f['diretta'])) {
         $nome = ins_foto($_FILES[$f['nome']], $_GET['cosa'] . $i, $descrizione);
     } elseif ($_FILES[$f['nome']]['tmp_name'] != '' && isset($f['diretta'])) {
         $nome = ins_file($_FILES[$f['nome']], $_GET['cosa'] . $i, $descrizione);
     } else {
         $nome = '';
     }
     if (substr($_GET['cosa'], $nome) || $nome == '') {
         $i++;
         mysql_query("update " . $_GET['cosa'] . " set " . $f['nome'] . "='" . $nome . "' where id_" . $_GET['cosa'] . "='" . $id_modello . "'") or die(mysql_error());
     }
 }
 if (isset($file)) {
     foreach ($file as $fi) {
         $newName = 'file_' . $id_modello;
         $nome = copyFile($_FILES[$fi['nome']], $newName);
         if ($nome !== false) {
Example #2
0
 function inserisci($_POST)
 {
     $query = "insert into " . $this->cosa . " (";
     $value = " values(";
     $i = 0;
     $foto = array();
     $file = array();
     $url = '';
     if ($this->cosa == 'utenti') {
         $url = HOMEPATH . "registrazione.php";
     } else {
         $url = ADMINPATH . "inserisci.php?cosa=" . $this->cosa;
     }
     if (isset($_REQUEST['url'])) {
         $url = $_REQUEST['url'];
     }
     $int = new interfaccia($this->_properties);
     $int->genera_controlli_php($url);
     foreach ($this->_properties as $s) {
         print $s['tipo'] . '<br />';
         if ($s['tipo'] != 'file' && $s['tipo'] != 'tab' && $s['tipo'] != 'tabs' && $s['tipo'] != 'titolo' && !isset($s['onsubmit'])) {
             if ($s['tipo'] == 'checkbox' && $s['nome'] != 'privacy') {
                 if (isset($s['unico']) && $_POST[$s['nome']] == '1') {
                     $query2 = "update " . $cosa . ' set ' . $s['nome'] . '=0';
                 }
                 if ($_POST[$s['nome']] != '1') {
                     $_POST[$s['nome']] = 0;
                 } else {
                     $_POST[$s['nome']] = 1;
                 }
             } elseif ($s['tipo'] == 'textarea' || $s['tipo'] == 'text') {
                 if (isset($s['unico']) && $_POST[$s['nome']] != '') {
                     $unico = mysql_query("select * from " . $cosa . " where " . $s['nome'] . "='" . $_POST[$s['nome']] . "'");
                     if (mysql_num_rows($unico) > 0) {
                         header("Location: ../index.php?ins=err2");
                         exit;
                     }
                 }
                 if ($s['controllo'] == 'data') {
                     $_POST[$s['nome']] = my_date($_POST[$s['nome']]);
                 } else {
                     if ($s['tipo'] == 'textarea' && !isset($s['codice'])) {
                         if (isset($s['editor'])) {
                             $_POST[$s['nome']] = htmlentities($_POST[$s['nome']]);
                         }
                     } elseif (!isset($s['codice'])) {
                         $_POST[$s['nome']] = addslashes(htmlentities($_POST[$s['nome']]));
                     } else {
                         $_POST[$s['nome']] = addslashes($_POST[$s['nome']]);
                     }
                 }
             }
             if ($i == 0) {
                 if ($s['nome'] != 'privacy') {
                     $query .= $s['nome'];
                     $value .= "'" . $_POST[$s['nome']] . "'";
                     $i++;
                 }
             } else {
                 if ($s['nome'] != 'privacy') {
                     $query .= ',' . $s['nome'];
                     $value .= ",'" . $_POST[$s['nome']] . "'";
                 }
             }
         } elseif (isset($s['genere']) && !isset($s['onsubmit'])) {
             $file[] = $s;
         } elseif (!isset($s['onsubmit'])) {
             $foto[] = $s;
         }
     }
     if (isset($query2)) {
         mysql_query($query2) or die(mysql_error());
     }
     if ($this->cosa == 'utenti') {
         $_POST['verificato'] = gen_password();
         $query .= ',verificato';
         $value .= ",'" . $_POST['verificato'] . "'";
     }
     $query .= ')';
     $value .= ')';
     //print $query.$value;
     mysql_query($query . $value) or die(mysql_error());
     $id_modello = mysql_insert_id();
     $descrizione = $id_modello;
     $_POST['id'] = $id_modello;
     $i = 0;
     if (isset($foto)) {
         foreach ($foto as $f) {
             if ($_FILES[$f['nome']]['tmp_name'] != '') {
                 $nome = ins_foto($_FILES[$f['nome']], $cosa . $i, $descrizione);
             } else {
                 $nome = '';
             }
             if (strpos($nome, $cosa) || $nome == '') {
                 $i++;
                 mysql_query("update " . $cosa . " set " . $f['nome'] . "='" . $nome . "' where id_" . $cosa . "='" . $id_modello . "'") or die(mysql_error());
             }
         }
     }
     if (isset($file)) {
         foreach ($file as $fi) {
             $newName = 'tool' . $id_modello;
             $nome = copyFile($_FILES[$fi['nome']], $newName);
             if ($nome !== false) {
                 $i++;
                 mysql_query("update " . $cosa . " set " . $fi['nome'] . "='" . $nome . "' where id_" . $cosa . "='" . $id_modello . "'") or die(mysql_error());
             }
         }
     }
     if ($i == count($foto) + count($file)) {
         header("Location:" . $url . "&ins=ok");
         exit;
     } else {
         header("Location:" . $url . "&ins=err");
         exit;
     }
 }