]> git.mxchange.org Git - friendica.git/blobdiff - mod/profiles.php
removed testing cruft
[friendica.git] / mod / profiles.php
index a8b6858d798c125eedb0a1cc543c4275ccbc1395..8b44e2d59a7585fcabe1113fdad6401c2900d4f3 100644 (file)
@@ -10,8 +10,6 @@ function profiles_post(&$a) {
 
        // todo - delete... ensure that all contacts using the to-be-deleted profile are moved to the default.          
 
-
-
        if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
                $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($a->argv[1]),
@@ -21,6 +19,7 @@ function profiles_post(&$a) {
                        $_SESSION['sysmsg'] .= "Profile not found." . EOL;
                        return;
                }
+               $is_default = (($r[0]['is-default']) ? 1 : 0);
 
                $profile_name = notags(trim($_POST['profile_name']));
                if(! strlen($profile_name)) {
@@ -38,7 +37,8 @@ function profiles_post(&$a) {
                $marital = notags(trim(implode(', ',$_POST['marital'])));
                $homepage = notags(trim($_POST['homepage']));
                $about = str_replace(array('<','>','&'),array('&lt;','&gt;','&amp;'),trim($_POST['about']));
-
+               if(x($_POST,'profile_in_directory'))
+                       $publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
                if(! in_array($gender,array('','Male','Female','Other')))
                        $gender = '';
 
@@ -72,6 +72,20 @@ function profiles_post(&$a) {
 
                if($r)
                        $_SESSION['sysmsg'] .= "Profile updated." . EOL;
+
+
+               if($is_default) {
+                       $r = q("UPDATE `profile` 
+                       SET `publish` = %d
+                       WHERE `id` = %d AND `uid` = %d LIMIT 1",
+                       intval($publish),
+                       intval($a->argv[1]),
+                       intval($_SESSION['uid'])
+
+                       );
+               }
+
+
        }
 
 
@@ -117,6 +131,48 @@ function profiles_content(&$a) {
                goaway($a->get_baseurl() . '/profiles');
        }                
 
+       if(($a->argc > 2) && ($a->argv[1] == 'clone')) {
+
+               $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
+                       intval($_SESSION['uid']));
+               $num_profiles = count($r0);
+
+               $name = "Profile-" . ($num_profiles + 1);
+               $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                       intval($_SESSION['uid']),
+                       intval($a->argv[2])
+               );
+               if(! count($r1)) {
+                       notice("Profile unavailable to clone." . EOL);
+                       return;
+               }
+               unset($r1[0]['id']);
+               $r1[0]['is-default'] = 0;
+               $r1[0]['publish'] = 0;  
+               $r1[0]['profile-name'] = dbesc($name);
+
+               dbesc_array($r1[0]);
+
+               $r2 = q("INSERT INTO `profile` (`" 
+                       . implode("`, `", array_keys($r1[0])) 
+                       . "`) VALUES ('" 
+                       . implode("', '", array_values($r1[0])) 
+                       . "')" );
+
+               $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
+                       intval($_SESSION['uid']),
+                       dbesc($name)
+               );
+               $_SESSION['sysmsg'] .= "New profile created." . EOL;
+               if(count($r3) == 1)
+                       goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
+       goaway($a->get_baseurl() . '/profiles');
+       return; // NOTREACHED
+       }                
+
+
+
+
 
        if(intval($a->argv[1])) {
                $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -134,9 +190,15 @@ function profiles_content(&$a) {
                require_once('view/profile_selectors.php');
 
                $tpl = file_get_contents('view/jot-header.tpl');
-               $profile_in_dir = file_get_contents("view/profile-in-directory.tpl");
+               $opt_tpl = file_get_contents("view/profile-in-directory.tpl");
+               $profile_in_dir = replace_macros($opt_tpl,array(
+                       '$yes_selected' => (($r[0]['publish']) ? " checked=\"checked\" " : ""),
+                       '$no_selected' => (($r[0]['publish'] == 0) ? " checked=\"checked\" " : "")
+               ));
+
 
                $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
+               $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
        
 //             $a->page['aside'] = file_get_contents('view/sidenote.tpl');     
                $is_default = (($r[0]['is-default']) ? 1 : 0);