Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- internetking created topic »password problem« 10:33 PM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 07:01 AM
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 06:41 AM
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 06:27 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Problem when modifying text files
-
- Rank: Registered User
- Registered: Sep 12, 2002
- Last visit: Mar 23, 2009
- Posts: 47
I have a script that writes the story a user add into a text file.. then I want the user to be able to modify the script. I manage to load the contents of the file into a textbox, but not to save the edited contents on the old file. Is there anyone who could take a few seconds to look at my script? Most likely its easy for you whizzes out there :D -
- Rank: Registered User
- Registered: Sep 12, 2002
- Last visit: Mar 23, 2009
- Posts: 47
I cut some unimportant stuff in the begging of these code clips.
Code
function Writer_storiesapi_create($args)
{
extract($args);
if (!pnSecAuthAction(0, 'Writer::', 'user::', ACCESS_ADD)) {
pnSessionSetVar('errormsg', _MODULENOAUTH1a);
return false;
}
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$Storiestable =&$pntable['writer_stories'];
$Storiescolumn =&$pntable['writer_stories_column'];
$nextId = $dbconn->GenId($Storiestable);
$parentstoryid = $nextId;
list($cat_id,
$parentstoryid,
$title,
$summary,
$story,
$ratingid,
$image,
$char1,
$char2,
$genre,
$author,
$date,
$updated,
$roundrobin,
$counter,
$keywords) = pnVarPrepForStore($cat_id,
$parentstoryid,
$title,
$summary,
$story,
$ratingid,
$image,
$char1,
$char2,
$genre,
$author,
$date,
$updated,
$roundrobin,
$counter,
$keywords);
$sql = "INSERT INTO $Storiestable (
$Storiescolumn[storyid],
$Storiescolumn[cat_id],
$Storiescolumn[parentstoryid],
$Storiescolumn[title],
$Storiescolumn[summary],
$Storiescolumn[story],
$Storiescolumn[ratingid],
$Storiescolumn[image],
$Storiescolumn[char1],
$Storiescolumn[char2],
$Storiescolumn[genre],
$Storiescolumn[author],
$Storiescolumn[date],
$Storiescolumn[updated],
$Storiescolumn[roundrobin],
$Storiescolumn[counter],
$Storiescolumn[keywords])
VALUES (
'".(int)$nextId."',
'".(int)$cat_id."',
'".$parentstoryid."',
'".$title."',
'".$summary."',
'".$story."',
'".$ratingid."',
'".$image."',
'".$char1."',
'".$char2."',
'".$genre."',
'".$author."',
'".$date."',
'".$updated."',
'".(int)$roundrobin."',
'".(int)$counter."',
'".$keywords."'
)";
$dbconn->Execute($sql);
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _EXAMPLECREATEFAILED);
return false;
}
$sql= "SELECT $Storiescolumn[storyid] FROM $Storiestable
WHERE $Storiescolumn[title] = '".$title."'";
$result = $dbconn->Execute($sql);
list($storyid) = $result->fields;
$dirname = "modules/Writer/stories/".$author."/";
$filename = "modules/Writer/stories/".$author."/".$storyid.".txt";
if (file_exists($dirname)) {
$handle = fopen($filename, 'w');
fwrite($handle, $story);
fclose($filename);
chmod ($filename, 0777);
} else {
mkdir($dirname, 0777);
$handle = fopen($filename, 'w');
fwrite($handle, $story);
fclose($filename);
chmod ($filename, 0777);
}
$storyid = $dbconn->PO_Insert_ID($Storiestable, $Storiescolumn['storyid']);
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _EXAMPLECREATEFAILED);
return false;
}
pnModCallHooks('item', 'create', $storyid, 'storyid');
return $storyid;
}
Edit section:
Code
if (!pnModAPILoad('Writer', 'stories')) {
pnSessionSetVar('errormsg', _LOADFAILED);
return false;
}
$item = pnModAPIFunc('Writer',
'stories',
'get',
array('storyid' => $storyid));
if (!$item) {
pnSessionSetVar('errormsg', _EXAMPLENOSUCHITEMb);
return false;
}
if (!pnSecAuthAction(0, 'Writer::', "$item[name]::$storyid", ACCESS_EDIT)) {
pnSessionSetVar('errormsg', _MODULENOAUTH3);
return false;
}
if (!pnSecAuthAction(0, 'Writer::', "$title::$storyid", ACCESS_EDIT)) {
pnSessionSetVar('errormsg', _MODULENOAUTH4);
return false;
}
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$Storiestable =&$pntable['writer_stories'];
$Storiescolumn =&$pntable['writer_stories_column'];
list( $cat_id,
$parentstoryid,
$title,
$summary,
$story,
$ratingid,
$image,
$char1,
$char2,
$genre,
$author,
$date,
$updated,
$roundrobin,
$counter,
$keywords,
$storyid) = pnVarPrepForStore($cat_id,
$parentstoryid,
$title,
$summary,
$story,
$ratingid,
$image,
$char1,
$char2,
$genre,
$author,
$date,
$updated,
$roundrobin,
$counter,
$keywords,
$storyid);
$sql = "UPDATE $Storiestable
SET $Storiescolumn[cat_id] = '".(int)$cat_id."',
$Storiescolumn[parentstoryid] = '".(int)$parentstoryid."',
$Storiescolumn[title] = '".$summary."',
$Storiescolumn[ratingid] = '".(int)$ratingid."',
$Storiescolumn[image] = '".$image."',
$Storiescolumn[char1] = '".$char1."',
$Storiescolumn[char2] = '".$char2."',
$Storiescolumn[genre] = '".$genre."',
$Storiescolumn[author] = '".$author."',
$Storiescolumn[date] = '".$date."',
$Storiescolumn[roundrobin] = '".(int)$roundrobin."',
$Storiescolumn[counter] = '".(int)$counter."',
$Storiescolumn[keywords] = '".$keywords."'
WHERE $Storiescolumn[storyid] = '".$storyid."'";
$dbconn->Execute($sql);
print_r($sql);
$dirname = "modules/Writer/stories/".$author."/";
$filename = "modules/Writer/stories/".$author."/".$storyid.".txt";
$handle = fopen($filename, 'w+');
fwrite($handle, $story);
fclose($filename);
chmod ($filename, 0777);
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _EXAMPLEUPDATEFAILED21);
return false;
}
$pnRender =& new pnRender('Writer');
$pnRender->clear_cache(null, $storyid);
return true;
}
Any clues? -
- Rank: Registered User
- Registered: Sep 12, 2002
- Last visit: Mar 23, 2009
- Posts: 47
-
- Rank: Registered User
- Registered: Sep 12, 2002
- Last visit: Mar 23, 2009
- Posts: 47
- Moderated by:
- Support
