22.1. Duplicating the PHP-Nuke FAQ module

Suppose you would like to have two FAQ modules. You might of course ask why on earth you would want such a complication in your PHP-Nuke site, but if you recall that PHP-Nuke lets you decide for each module individually whether to all visitors, only registered ones, or only administrators to view it, you will find out that two identical FAQ modules would be a simple way to have two FAQs, one only for administrators and one for all users.

We will now follow the steps outlined above for the purpose of duplicating the FAQ module:

Finally, we activate the Admin-FAQ module and specify that it can be viewed only by administrators.

CautionDon't forget the "op"s!
 

If you want your duplicate module to perform slightly different functions than the original one, there is no way around to creating duplicate "op" functions to be called from the "switch($op)" part of the admin file. In our example, this would mean that we would change

switch($op) {
 case "FaqCatSave":
   FaqCatSave($id_cat, $categories, $flanguage); /* Multilingual Code : added variable */
   break;
 case "FaqCatGoSave":
   FaqCatGoSave($id, $question, $answer);
   break;
 case "FaqCatAdd":
   FaqCatAdd($categories, $flanguage); /* Multilingual Code : added variable */
   break;
 case "FaqCatGoAdd":
   FaqCatGoAdd($id_cat, $question, $answer);
   break;
 case "FaqCatEdit":
   FaqCatEdit($id_cat);
   break;
 case "FaqCatGoEdit":
   FaqCatGoEdit($id);
   break;
 case "FaqCatDel":
   FaqCatDel($id_cat, $ok);
   break;
 case "FaqCatGoDel":
   FaqCatGoDel($id, $ok);
   break;
 case "FaqAdmin":
   FaqAdmin();
   break;
 case "FaqCatGo":
   FaqCatGo($id_cat);
   break;
}
} else {
 echo "Access Denied";
}

in the admin/modules/adminfaq.php file, to:

switch($op) {
 case "FaqCatSave2":
   FaqCatSave2($id_cat, $categories, $flanguage); /* Multilingual Code : added variable */
   break;
 case "FaqCatGoSave2":
   FaqCatGoSave2($id, $question, $answer);
   break;
 case "FaqCatAdd2":
   FaqCatAdd2($categories, $flanguage); /* Multilingual Code : added variable */
   break;
 case "FaqCatGoAdd2":
   FaqCatGoAdd2($id_cat, $question, $answer);
   break;
 case "FaqCatEdit2":
   FaqCatEdit2($id_cat);
   break;
 case "FaqCatGoEdit2":
   FaqCatGoEdit2($id);
   break;
 case "FaqCatDel2":
   FaqCatDel2($id_cat, $ok);
   break;
 case "FaqCatGoDel2":
   FaqCatGoDel2($id, $ok);
   break;
 case "FaqAdmin2":
   FaqAdmin2();
   break;
 case "FaqCatGo2":
   FaqCatGo2($id_cat);
   break;
}
} else {
 echo "Access Denied";
}

and then program the new functionality into the new functions (the ones with the 2 suffix in their name).