Location: PHPKode > projects > Polaring > view/configuration.php
<?php 
// vim: sw=4:ts=4
/**
* @version 00.04.09
* @package polaring
* @license This component in released under the GNU/GPL License
*
* File: view/configuration.php
* Role: Sets configuration
*
**/

class setup {

    function giveSettings() {
	echo "<h2>".strings::expression("setup", "Settings")."</h2>\n".
	    "<form action=\"".give::phpindex()."?section=setup".
	    "&amp;mission=write\" method=\"post\" >\n".
	    "<table class=\"config\" >\n".
	    "  <tfoot>\n".
	    "    <tr>\n".
	    "      <td><input type=\"submit\" name=\"submit\" id=\"submit\" ".
	    "value=\"".strings::expression("setup", "Submit")."\" /></td>\n".
	    "    </tr>\n".
	    "  </tfoot>\n".
	    "  <tbody>\n".
	    // Personal information
	    "    <tr>\n".
	    "      <td><h3>".strings::expression("setup", "Personal_information")."</h3><p>".
	    "<hr /></p></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"user\" >".strings::expression("setup", "Name").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"user\" name=\"user\" ".
	    "value=\"".$_SESSION['userName']."\" /></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"hrmax\">".strings::expression("polar", "hrMax").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"hrmax\" name=\"hrmax\" value=\"".
	    $_SESSION['maxHr']."\" /></td>\n".
	    "    </tr>\n".
	    // Page settings
	    "    <tr>\n".
	    "      <td><h3>".strings::expression("setup", "Page_settings")."<h3><p><hr /></p>".
	    "</td>\n".
	    "    </tr>\n".
	    // menumode
	    "    <tr>\n".
	    "      <td><label for=\"menumode\">".strings::expression("setup", "MenuMode").
	    "</label></td>\n".
	    "      <td><select id=\"menumode\" name=\"menumode\">\n".
	    "        <option value=\"0\" ";
	if ( $_SESSION['menumode'] == "0" ) {
	    echo "selected=\"1\"";
	}
	echo ">".strings::expression("setup", "tabbed")."</option>\n".
	    "        <option value=\"1\" ";
	if ( $_SESSION['menumode'] == "1" ) {
	    echo "selected=\"1\"";
	}
	echo ">".strings::expression("setup", "leftColMenu")."</option>\n".
	    "      </select></td>\n".
	    "    </tr>\n".
	// translation
	    "    <tr>\n".
	    "      <td><label for=\"translation\">".strings::expression("setup", "Translation").
	    "</label></td>\n".
	    "      <td><select id=\"translation\" name=\"translation\">\n";
	    $translationFiles = strings::giveTranslationfiles();
	foreach ( $translationFiles as $trFile ) {
	    $trInfo = strings::translationInfo($trFile);
	    echo "        <option value=\"".$trFile."\" ";
	if ( $_SESSION['translationFile'] == $trFile ) {
	    echo "selected=\"1\" ";
	}
	    echo ">".$trInfo['language']." (".$trInfo['filename'].")</option>\n";
	}
	    echo "      </select></td>\n".
		"    </tr>\n";
	// Km/h or min/km
	echo "    <tr>\n".
	    "      <td><label for=\"unitSpeed\">".
	    strings::expression("setup", "UnitSpeed").
	    "</label></td>\n".
	    "      <td><select id=\"unitSpeed\" name=\"unitSpeed\">\n";
	echo "        <option value=\"km/h\" ";
	if ( $_SESSION['unitSpeed'] == "km/h" ) {
	    echo "selected=\"1\" ";
	}
	echo ">km/h</option>\n";
	echo "        <option value=\"min/km\" ";
	if ( $_SESSION['unitSpeed'] == "min/km" ) {
	    echo "selected=\"1\" ";
	}
	echo ">min/km</option>\n";
	echo "      </select>\n".
	    "      </td>\n".
	    "    </tr>\n";
	// Start of week -day
	echo "    <tr>\n".
	"      <td><label for=\"WeekStartday\">".strings::expression("setup", "WeekStartDay") .
	"</label></td>\n" .
	"      <td><select id=\"WeekStartDay\" name=\"WeekStartDay\">\n";
	$WeekStartDay = $_SESSION['weekStartDay'];
	for ($i=0; $i < 7; $i++) {
	    $iDay = giveWeekDay($i);
	    echo "        <option value=\"".$i."\" ";
	    if ( $WeekStartDay == $i ) {
		echo "selected=\"1\" ";
	    }
	    echo ">".$iDay."</option>\n";
	}
	echo "      </select></td>\n".
	    "    </tr>\n"; 
      
	// Footer
	echo "    <tr>\n".
	    "      <td><label for=\"footer\">".strings::expression("setup", "Footer").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"footer\" name=\"".
	    "footer\" value=\"".str_replace('"', '&quot;', $_SESSION['footer'])."\" /></td>\n".
	    "    </tr>\n";

	// Valid IP for settings
	echo "    <tr>\n".
	    "      <td colspan=\"2\"><h3>".
	    strings::expression("setup", "ValidIp").
	    "</h3><p>".strings::expression("setup", "whyValidIp").
	    "<hr /></p></td>\n".
	    "    </tr>\n";
	echo "    <tr>\n".
	    "      <td><label for=\"ip_settings\">".strings::expression("setup", "Settings")."</label></td>\n".
	    "      <td><input type=\"text\" id=\"ip_settings\" name=\"ip_settings\" value=\"".
	    $_SESSION['validIp']['settings']."\" /></td>\n".
	    "    </tr>\n";
    // Valid IP for tools
	echo "    <tr>\n".
	    "      <td><label for=\"ip_tools\">".strings::expression("navigation", "Tools").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"ip_tools\" name=\"ip_tools\" value=\"".
	    $_SESSION['validIp']['tools']."\" /></td>\n".
	    "    </tr>\n";
    // Valid IP for diary
	echo "    <tr>\n".
	    "      <td><label for=\"ip_diary\">".strings::expression("navigation", "diary").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"ip_diary\" name=\"ip_diary\" value=\"".
	    $_SESSION['validIp']['diary']."\" /></td>\n".
	    "    </tr>\n";
	echo "    <tr>\n".
	    "      <td><label for=\"ip_upload\">".
	    strings::expression("navigation", "uploadWorkout").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"ip_upload\" ".
	    "name=\"ip_upload\" value=\""
	    .$_SESSION['validIp']['upload']."\" /></td>\n".
	    "    </tr>\n";
    // JPGRAPH SETTINGS
	echo "    <tr>\n".
	    "      <td colspan=\"2\"><h3>".strings::expression("setup",
	    "Jpgraph_settings")."</h3><p>".
	    strings::expression("setup", "whyJpgraph").
	    "<hr /></p></td>\n".
	    "    </tr>\n".
    // dir
	    "    <tr>\n".
	    "      <td><label for=\"dirJpgraph\">".strings::expression("setup", "dirJpgraph").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"dirJpgraph\" name=\"dirJpgraph\" ".
	    "value=\"".give::dirJpgraph()."\" /></td>\n".
	    "    </tr>\n".
    // tty-enabled (yes/no)
	    "    <tr>\n".
	    "      <td><label for=\"tty_enabled\">".
	    strings::expression("setup", "tty_enabled").
	    "</label></td>\n".
	    "      <td><select name=\"tty_enabled\" id=\"tty_enabled\">\n".
	    "        <option value=\"1\" ";
	if ( $_SESSION['tty']['enabled'] ) {
	    echo "selected=\"1\" ";
	}
	echo ">".strings::expression("common", "Yes")."</option>\n".
	    "        <option value=\"0\" ";
	if ( !$_SESSION['tty']['enabled'] ) {
	    echo "selected=\"1\" ";
	}
	echo ">".strings::expression("common", "No")."</option>\n".
	    "        </select></td>\n".
	    "    </tr>\n";
    // tty-path
	echo "    <tr>\n".
	    "      <td><label for=\"dirTTY\">".
	    strings::expression("setup", "dirTTY").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"dirTTY\" ".
	    "name=\"dirTTY\" value=\"".
	    $_SESSION['dirTTY']."\" /></td>\n".
	    "    </tr>\n";

    // MySQL settings
	echo "    <tr>\n".
	    "      <td colspan=\"2\"><h3>".strings::expression("setup", "Mysql_settings").
	    "</h3>\n          <p>".strings::expression("setup", "whyMysql")."<hr /></p></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"mysql_on\">".strings::expression("setup", "mysql_on").
	    "</label></td>\n".
	    "      <td><select name=\"mysql_on\" id=\"mysql_off\">\n".
	    "        <option value=\"1\" ";
	if ( $_SESSION['mysql']['on'] ) {
	    echo "selected=\"1\" ";
	}
	echo ">".strings::expression("setup", "On")."</option>\n".
	    "        <option value=\"0\" ";
	if ( !$_SESSION['mysql']['on'] ) {
	    echo "selected=\"1\" ";
	}
	echo ">".strings::expression("setup", "Off")."</option>\n".
	    "        </select></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"mysql_server\">".strings::expression("setup", "Server").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"mysql_server\" ".
	    "name=\"mysql_server\" value=\"".$_SESSION['mysql']['server'].
	    "\" /></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"mysql_table\">".strings::expression("setup", "Table").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"mysql_table\" name=".
	    "\"mysql_table\" value=\"".$_SESSION['mysql']['table']."\" /></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"mysql_user\">".strings::expression("setup", "User").
	    "</label></td>\n".
		  "      <td><input type=\"text\" id=\"mysql_user\" name=\"mysql_user\" ".
	    "value=\"".$_SESSION['mysql']['user']."\" /></td>\n".
	    "    </tr>\n".
	    "    <tr>\n".
	    "      <td><label for=\"mysql_password\">".strings::expression("setup", "Password").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"mysql_password\" name=\"".
	    "mysql_password\" value=\"".$_SESSION['mysql']['password']."\" /></td>\n".
	    "    </tr>\n";
    // Pathways
	echo "    <tr>\n".
	    "      <td colspan=\"2\"><h3>".strings::expression("setup", "Pathways").
	    "</h3>\n          <p>".strings::expression("setup", "whyDirs")."<hr /></p></td>\n".
	    "    </tr>\n";
    // workout-dir
	echo "    <tr>\n".
	    "      <td><label for=\"dirWorkouts\">".
	    strings::expression("setup", "dirWorkouts")."</label></td>\n".
	    "      <td><input type=\"text\" id=\"dirWorkouts\" name=".
	    "\"dirWorkouts\" value=\"".$_SESSION['dirTrFiles']."\" /></td>\n".
	    "    </tr>\n";
    // userdata-dir
	echo "    <tr>\n".
	    "        <td><label for=\"dirUserdata\">".
	    strings::expression("setup", "dirUserdata")."</label>".
	    "</td>\n".
	    "        <td><input type=\"text\" id=\"dirUserdata\" ".
	    "name=\"dirUserdata\" value=\"".$_SESSION['dirUserdata'].
	    "\" /></td>\n".
	    "    </tr>\n";
    // upload-dir
	echo "    <tr>\n".
	    "        <td><label for=\"dirUpload\">".
	    strings::expression("setup", "dirUpload")."</label>".
	    "</td>\n".
	    "        <td><input type=\"text\" id=\"dirUpload\" ".
	    "name=\"dirUpload\" value=\"".$_SESSION['dirUpload'].
	    "\" /></td>\n".
	    "    </tr>\n";
    // temp-dir
	echo "    <tr>\n".
	    "        <td><label for=\"dirTemp\">".
	    strings::expression("setup", "dirTemp")."</label>".
	    "</td>\n".
	    "        <td><input type=\"text\" id=\"dirTemp\" ".
	    "name=\"dirTemp\" value=\"".$_SESSION['dirTemp'].
	    "\" /></td>\n".
	    "    </tr>\n";
	    // s710-dir
	echo "    <tr>\n".
	    "      <td><label for=\"dirS710\">".strings::expression("setup", "dirS710").
	    "</label></td>\n".
	    "      <td><input type=\"text\" id=\"dirS710\" name=\"dirS710\" ".
	    "value=\"".$_SESSION['dirS710']."\" /></td>\n".
	    "    </tr>\n";
    // unzip-dir
	echo "    <tr>\n".
	    "        <td><label for=\"dirUnzip\">".strings::expression("setup", "dirUnzip").
	    "</label></td>\n".
	    "        <td><input type=\"text\" id=\"dirUnzip\" name=\"dirUnzip\" ".
	    "value=\"".$_SESSION['dirUnzip']."\" /></td>\n".
	    "    </tr>\n";
    // GOOGLE MAPS
	echo "    <tr>\n".
	    "      <td colspan=\"2\"><h3>".strings::expression("setup", "GMaps_settings")."</h3>\n".
	    "<p>".strings::expression("setup", "whyGMaps")."</p><hr /></td>".
	    "    </tr>\n";
    // map points
	echo "    <tr>\n".
	    "        <td><label for=\"mapPoints\">".strings::expression("setup", "mapPoints").
	    "</label></td>\n".
	    "        <td><input type=\"text\" id\"mapPoints\" name=\"mapPoints\" ".
	    "value=\"".$_SESSION['mapPoints']."\" /></td>\n".
	    "    </tr>\n";
    // api 
	echo "    <tr>\n".
	    "      <td><label for=\"gmapsApi\">".strings::expression("setup", "ApiKey")."</label></td>\n".
	    "      <td><input type=\"text\" id=\"gmapsApi\" name=\"gmapsApi\" value=\"".$_SESSION['gmapsApi']."\" /></td>\n".
	    "    </tr>\n";
    // END SETTINGS TABLE
	echo "  </tbody>\n".
	    "</table>\n".
	    "</form>\n";
    } // end function giveSettings


    function writeSettings() {
	$config = "<?php\n".
	    "// vim: sw=4:ts=4\n".
	    "/**\n".
	    "* @version USER SAVED SETTINGS\n".
	    "* @package polaring\n".
	    "*\n".
	    "* File: configuration.php\n".
	    "* Role: Users own variables\n".
	    "**/\n".
	    "\n".
	    "//////////////////////////////////\n".
	    "// PERSONAL INFORMATION\n".
	    "//////////////////////////////////\n".
	    "\n".
	    "// User name (thus far, mainly used for diary)\n".
	    "\$configUser = \"".$_POST['user']."\";\n".
	    "// Users max-hr (temporary; will be set differently in the future)\n".
	    "\$configMaxhr = ".$_POST['hrmax']."; // MaxHR\n".
	    "\n".
	    "\n".
	    "//////////////////////////////////\n".
	    "// PAGE SETTINGS\n".
	    "//////////////////////////////////\n".
	    "\n".
	    "\$configMenuMode = \"".$_POST['menumode']."\"; // 0 = tab (default); 1 = left-column menu\n".
	    "\$configTranslation = \"".$_POST['translation']."\";\n".
	    "\$configUnitSpeed = \"".$_POST['unitSpeed']."\"; // km/h or min/km\n".
	    "\$configWeekStartDay = \"".$_POST['WeekStartDay']."\"; /* week starts on?".
	    " YET TO BE IMPLEMENTED\n".
	    "0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday */\n".
	    "\n".
	    "\$configFooter = \"".str_replace("&quot;", '"', $_POST['footer']).
	    "\"; // Footer (can be used for site-image, external link, or whatever.\n".
	    "\n".
	    "// Valid ip for viewing\n".
	    "\$configValidIp['settings'] = \"".$_POST['ip_settings']."\";\n".
	    "\$configValidIp['tools'] = \"".$_POST['ip_tools']."\";\n".
	    "\$configValidIp['diary'] = \"".$_POST['ip_diary']."\";\n".
	    "\$configValidIp['upload'] = \"".$_POST['ip_upload']."\";\n".
	    "\n".
	    "\n".
	    "//////////////////////////////////\n".
	    "// Jpgraph settings\n".
	    "//////////////////////////////////\n".
	    "\n".
	    "// Path to jpgraph\n".
	    "// (needed for graphs)\n".
	    "\$configJpgraphdir = \"".$_POST['dirJpgraph']."\";\n".
	    "\$configJpgraphTTYenabled = ";
	if ( $_POST['tty_enabled'] ) {
	    $config .= "true";
	} else {
	    $config .= "false";
	}
	$config .= ";\n".
	    "\$configTTYpath = \"".$_POST['dirTTY']."\";\n".
	    "\n".
	    "\n".
	    "//////////////////////////////////\n".
	    "// MySQL settings\n".
	    "//////////////////////////////////\n".
	    "\n".
	    "\$configMySQL['on'] = ";
	if ( $_POST['mysql_on'] ) {
	    $config .= "true";
	} else {
	    $config .= "false";
	}
	$config .= "; // Use MySQL, true/false\n".
	    "\$configMySQL['server'] = \"".$_POST['mysql_server']."\"; // server\n".
	    "\$configMySQL['table'] = \"".$_POST['mysql_table']."\"; // table\n".
	    "\$configMySQL['user'] = \"".$_POST['mysql_user']."\"; // user\n".
	    "\$configMySQL['password'] = \"".$_POST['mysql_password'].
	    "\"; // password\n".
	    "\n".
	    "\n".
	    "//////////////////////////////////\n".
	    "// PATHWAYS\n".
	    "//////////////////////////////////\n".
	    "\n".
	// workouts
	    "// Path to workouts\n".
	    "\$configExercisedir = \"".$_POST['dirWorkouts']."\";\n".
	// userdata
	    "// Path to userdata *MUST BE WRITABLE*\n".
	    "\$configUserdatadir = \"".$_POST['dirUserdata']."\";\n".
	// upload
	    "// Path to upload-dir *MUST BE WRITABLE (for uploading)*\n".
	    "\$configUploaddir = \"".$_POST['dirUpload']."\";\n".
	// temp
	    "// Where to store temporary files *MUST BE WRITABLE*\n".
	    "\$configTempdir = \"".$_POST['dirTemp']."\";\n".
	// s710
	    "// Path to s710\n".
	    "// (Currently, srd2hrm is required. This may change in the future ".
	    "however.)\n".
	    "\$configS710dir = \"".$_POST['dirS710']."\";\n".
	// unzip
	    "// Path to unzip -- if left empty, zip support is disabled\n".
	    "\$configUnzipdir = \"".$_POST['dirUnzip']."\";\n".
	    "\n";
	$config .= "\n".
	    "//////////////////////////////////\n".
	    "// GOOGLE MAPS\n".
	    "//////////////////////////////////\n".
	    "\n".
	    "// Amount of points in the google-map\n".
	    "//    100 = default\n".
	    "//      0 = *every*\n".
	    "\$configMapPoints = \"".$_POST['mapPoints']."\";\n".
	    "\$configGmapsApi = \"".$_POST['gmapsApi']."\";\n\n";
	// end config
	$config .= "?>\n";

	$config_file = "./configuration.php";
	if ( $output = fopen($config_file, "w") ) {
	    fputs($output, $config, strlen($config));
	    fclose($output);
	    echo "<p>".strings::expression("setup", "settings_saved")."</p>\n";
	    visa::tillbaka("2");
	} else {
	    echo "<p>".strings::expression("error", "open_file").": <em>".$config_file.
	    "</em></p>\n";
	visa::tillbaka("2");
	}

    } // end function writeSettings

} // end class setup


?>
Return current item: Polaring