spawner2.php the revenge :) spawner2.php the revenge :)
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

spawner2.php the revenge :)

Started by ypp, December 01, 2005, 12:28:07 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

ypp

Hello, I'm not a php programmer but I'm trying to modify spawner.php to get categories in batch mode
because I've to add a lot of categories.

Example:

North America (cat)
       Cars (sub-cat)
       Design (sub-cat)
       Architecture (sub-cat)
       Food (sub-cat)
       etc. etc... 40 sub-categories


   Asia (cat)
       Cars (sub-cat)
       Design (sub-cat)
       Architecture (sub-cat)
       Food (sub-cat)
       etc. etc... 40 sub-categories


The same thing is for Europe, Hispano América, Oceania and Africa...everyone of these with the same 40 sub-categories...
So I modified spawner.php but when I try to upload a file with the category list I get this error: "There was an error while processing a database query"


Below the spawner2.php code:

<?php

define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

if (!
GALLERY_ADMIN_MODEcpg_die(ERROR$lang_errors['access_denied'], __FILE____LINE__);


pageheader('Category spawner');

starttable('100%''Category spawner');


if (
count($_FILES)){

if ($_FILES['userfile']['error']) die('Upload error ' $_FILES['userfile']['error']);


$data file($_FILES['userfile']['tmp_name']);
$category = (int) $_POST['category'];
$description addslashes($_POST['description']);

foreach ($data as $id => $category){
$result cpg_db_query("INSERT INTO {$CONFIG['TABLE_CATEGORIES']} (`title`, `category`, `description`) VALUES ('$title', '$category', '$description')");
$status mysql_affected_rows() ? "Category '$category' added" "<font color=\"red\">Category'$category' not added</font>" ;
echo '<tr><td class="tableb" align="center">'.$status.'</td></tr>';
}

} else {

function get_subcat_data($parent$ident '')
{
     global $CONFIG$CAT_LIST;

     $result cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent' AND cid != 1 ORDER BY pos");
     if (mysql_num_rows($result) > 0) {
         $rowset cpg_db_fetch_rowset($result);
         foreach ($rowset as $subcat) {
             $CAT_LIST[] = array($subcat['cid'], $ident $subcat['name']);
             get_subcat_data($subcat['cid'], $ident '&nbsp;&nbsp;&nbsp;');
         }
     }
}

$CAT_LIST = array();
     $CAT_LIST[] = array(0'* No category *');
     get_subcat_data(0'');

$cats '<select name="category" class="listbox">';

     foreach($CAT_LIST as $category) {
         $cats .='<option value="' $category[0] . '"' . ($cat == $category[0] ? ' selected''') . ">" $category[1] . "</option>\n";
     }

$cats .= '</select>';


echo <<< EOT
<tr>
 <td class="tableb" align="center">

<form action="spawner2.php" METHOD="post" enctype="multipart/form-data">
<p>Upload a file to import<input name="userfile" type="file" size="50" /></p>
<p>Default category description: <input type="text" name="description" size="50" value="" /></p>
<p>
$cats</p>
<br />
<p><input type="submit" value="Spawn2" /></p>
</form>
</td>
</tr>

EOT;


}

endtable();
pagefooter();
?>



Please, Help ???

Nibbler

Enable debug mode, that will tell you what the problem is. I would think you'd need to change `title` to `name` and `category` to `parent`.

PS: what does this have to do with plugins ?

ypp

Thank you Nibbler :) , I've tried to change them and now it's possible to upload the file but for every new sub-cat I only obtain a blank row in the cat list... at the moment for me it's all difficult...

Scuse me, for the mistaken thread... :(