Hello guys and girls..
I have a problem with the media wiki endgine..
I want to create user groups via the UI, but these groups and permissions are static. (By static I mean that they are written in a php file that puts them into an array.)
The php file is 6000+ lines long.
I'm trying to read it until I reach the comment that I placed (// [Permissions start]), and then append a string after this line.
Sadly, when I open the file with the fopen($filePath, 'a') it doesn't work.. 'a+' Is for appending string in the end of the file, so I don't want to hear anything with it unless if you can thing of a solution with it.

Here is my code..

<!DOCTYPE html>
    <form action="" method="post"> 
    <input type="text" name="titleGr" /> <input type="submit" name="submit" value="submit" /><br />
    <input type="checkbox" name="checkGr[0]" value="1" /> per1<br /> <!-- checkboxes will set 1 or 0 -->
    <input type="checkbox" name="checkGr[1]" value="1"/> per2<br />


// Packing the temporary array with the permissions
    $wbGroupPer[$_POST['titleGr']] = array('per1_label'=>'0', 'per2_label'=>'0'); // setting false parameters inside the array

    $arrKeys = array_keys($wbGroupPer[$_POST['titleGr']]); // getting the keys in a temporary array

    foreach($_POST['checkGr'] as $key => $permission){ // organizing the temporary group array
        $wbGroupPer[$_POST['titleGr']][$arrKeys[$key]] = $permission; // setting permissions for the group


        $fileSize = filesize("D:\\xampp\\htdocs\\samples\\DefaultSettings.php"); // gets the file size in bytes

        $fileHandle = fopen("D:\\xampp\\htdocs\\samples\\DefaultSettings.php", 'r'); // opens the file for reading
        $i = 0;

        $oneLine = fgets($fileHandle);

            echo $i . ' ' . $oneLine . '<br />';
            $i = $i + 1;
            $oneLine = htmlspecialchars(fgets($fileHandle));

            if(stristr($oneLine, '[Permissions start]') === false){
                //File not found

                $fileHandle = fopen("D:\\xampp\\htdocs\\samples\\DefaultSettings.php", 'a');
                fwrite($fileHandle, '\r\n');

                for($i=0; $i<count($wbGroupPer[$_POST['titleGr']]); $i++){ // loop for setting the string
                    $cond = ($wbGroupPer[$_POST['titleGr']][$arrKeys[$i]]) ? 'true' : 'false'; // setting the boolean values
                    $saveString = '$wbGroupPermissions[' . $_POST['titleGr'] . '][' . $arrKeys[$i] .']=' . $cond; // setting the string for passing to the file
                    //file_put_contents("D:\\xampp\\htdocs\\samples\\DefaultSettings.php", $saveString, FILE_APPEND);
                    fwrite($fileHandle, $saveString);

        echo "File not found!!";

I've Uploaded the Default.php file for you..
I would be very happy If you help me out, or give me a good hint atleast.
And sorry about the bad condition of the code. It's just a test for media wiki.

Sorry, when I was posting the code I forgot to remove the second break on line 62.. So please ignore that line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.