contact editor

This commit is contained in:
Mike Macgirvin 2010-07-10 23:03:54 -07:00
parent b9bbe0cec2
commit a42c9616f9
7 changed files with 270 additions and 79 deletions

View file

@ -6,62 +6,56 @@ function edit_contact(&$a,$contact_id) {
function contacts_post(&$a) { function contacts_post(&$a) {
if(($a->argc != 3) || (! local_user())) if(! local_user())
return; return;
$contact_id = intval($a->argv[1]); $contact_id = intval($a->argv[1]);
if(! $contact_id) if(! $contact_id)
return; return;
dbg(2);
$cmd = $a->argv[2]; print_r($_POST);
$orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );
if(! count($r)) if(! count($orig_record)) {
return; notice("Could not access contact record." . EOL);
$photo = str_replace('-4.jpg', '' , $r[0]['photo']); goaway($a->get_baseurl() . '/contacts');
$photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d", return; // NOTREACHED
dbesc($photo),
intval($_SESSION['uid'])
);
switch($cmd) {
case 'edit':
edit_contact($a,$contact_id);
break;
case 'block':
$r = q("UPDATE `contact` SET `blocked` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id),
intval($_SESSION['uid'])
);
if($r)
$_SESSION['sysmsg'] .= "Contact has been blocked." . EOL;
break;
case 'drop':
$r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id),
intval($_SESSION['uid']));
if(count($photos)) {
foreach($photos as $p) {
q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
$p['id']);
}
}
if($intval($contact_id))
q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
intval($contact_id)
);
break;
default:
return;
break;
} }
$profile_id = intval($_POST['profile-assign']);
if($profile_id) {
$r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($profile_id),
intval($_SESSION['uid'])
);
if(! count($r)) {
notice("Cannot locate selected profile." . EOL);
return;
}
}
$rating = intval($_POST['reputation']);
if($rating > 5 || $rating < 0)
$rating = 0;
$reason = notags(trim($_POST['reason']));
$r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($profile_id),
intval($rating),
dbesc($reason),
intval($contact_id),
intval($_SESSION['uid'])
);
if($r)
notice("Contact updated." . EOL);
else
notice("Failed to update contact record." . EOL);
return;
} }
@ -75,6 +69,7 @@ function contacts_post(&$a) {
function contacts_content(&$a) { function contacts_content(&$a) {
if(! local_user()) { if(! local_user()) {
$_SESSION['sysmsg'] .= "Permission denied." . EOL; $_SESSION['sysmsg'] .= "Permission denied." . EOL;
return; return;
@ -82,6 +77,67 @@ function contacts_content(&$a) {
if($a->argc == 3) {
$contact_id = intval($a->argv[1]);
if(! $contact_id)
return;
$cmd = $a->argv[2];
$orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id),
intval($_SESSION['uid'])
);
if(! count($orig_record)) {
notice("Could not access contact record." . EOL);
goaway($a->get_baseurl() . '/contacts');
return; // NOTREACHED
}
$photo = str_replace('-4.jpg', '' , $r[0]['photo']);
$photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
dbesc($photo),
intval($_SESSION['uid'])
);
if($cmd == 'block') {
$blocked = (($orig_record[0]['blocked']) ? 0 : 1);
$r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($blocked),
intval($contact_id),
intval($_SESSION['uid'])
);
if($r) {
$msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
notice($msg);
}
goaway($a->get_baseurl() ."/contacts/$contact_id");
return; // NOTREACHED
}
if($cmd == 'drop') {
$r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id),
intval($_SESSION['uid']));
if(count($photos)) {
foreach($photos as $p) {
q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
$p['id']);
}
}
if($intval($contact_id))
q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
intval($contact_id)
);
notice("Contact has been removed." . EOL );
goaway($a->get_baseurl() . '/contacts');
return; // NOTREACHED
}
}
if(($a->argc == 2) && intval($a->argv[1])) { if(($a->argc == 2) && intval($a->argv[1])) {
@ -99,13 +155,33 @@ function contacts_content(&$a) {
$tpl = file_get_contents("view/contact_edit.tpl"); $tpl = file_get_contents("view/contact_edit.tpl");
$direction = '';
if(strlen($r[0]['issued-id'])) {
if(strlen($r[0]['dfrn-id'])) {
$direction = DIRECTION_BOTH;
$dir_icon = 'images/lrarrow.gif';
$alt_text = 'Mutual Friendship';
}
else {
$direction = DIRECTION_IN;
$dir_icon = 'images/larrow.gif';
$alt_text = 'is a fan of yours';
}
}
else {
$direction = DIRECTION_OUT;
$dir_icon = 'images/rarrow.gif';
$alt_text = 'you are a fan of';
}
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$profile_select' => contact_profile_assign($r[0]['profile-id']), '$profile_select' => contact_profile_assign($r[0]['profile-id']),
'$contact_id' => $r[0]['id'], '$contact_id' => $r[0]['id'],
'$blocked' => $r[0]['blocked'], '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
'$rating' => $r[0]['rating'], '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
'$rating' => contact_reputation($r[0]['rating']),
'$reason' => $r[0]['reason'], '$reason' => $r[0]['reason'],
// '$groups' => group_selector(), '$groups' => '', // group_selector(),
'$photo' => $r[0]['photo'], '$photo' => $r[0]['photo'],
'$name' => $r[0]['name'], '$name' => $r[0]['name'],
'$dir_icon' => $dir_icon, '$dir_icon' => $dir_icon,
@ -184,6 +260,4 @@ function contacts_content(&$a) {
} }
} }
return $o; return $o;
} }

View file

@ -292,7 +292,7 @@ function profiles_content(&$a) {
'$baseurl' => $a->get_baseurl(), '$baseurl' => $a->get_baseurl(),
'$profile_id' => $r[0]['id'], '$profile_id' => $r[0]['id'],
'$profile_name' => $r[0]['profile-name'], '$profile_name' => $r[0]['profile-name'],
'$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.</p>" : ""), '$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.</p>" : ""),
'$name' => $r[0]['name'], '$name' => $r[0]['name'],
'$dob' => dob($r[0]['dob']), '$dob' => dob($r[0]['dob']),
'$hide_birth' => (($r[0]['dob_hide']) ? " checked=\"checked\" " : ""), '$hide_birth' => (($r[0]['dob_hide']) ? " checked=\"checked\" " : ""),

View file

@ -1,34 +1,61 @@
<h2>Contact Editor</h2>
<div id="contact-edit-banner-name">$name</div>
<div id="contact-edit-wrapper" > <div id="contact-edit-wrapper" >
<div class="contact-edit-photo-wrapper" >
<div id="contact-edit-photo-wrapper" >
<img id="contact-edit-direction-icon" src="$dir_icon" alt="$alt_text" title="$alt_text" /> <img id="contact-edit-direction-icon" src="$dir_icon" alt="$alt_text" title="$alt_text" />
<div id="contact-edit-photo" > <div id="contact-edit-photo" >
<a href="$url" title="Visit $name's profile" /><img src="$photo" alt="$name" /></a> <a href="$url" title="Visit $name's profile" /><img src="$photo" alt="$name" /></a>
</div> </div>
<div id="contact-edit-photo-end" ></div> <div id="contact-edit-photo-end" ></div>
</div> </div>
<div id="contact-edit-nav-wrapper" <div id="contact-edit-nav-wrapper" >
<div id="contact-edit-name" >$name</div>
<div id="contact-edit-break"></div>
<form action="contacts" method="post" >
<input type="hidden" name="contact_id" value="$contact_id">
<div id="contact-edit-links" > <div id="contact-edit-links" >
<a href="contacts/$id/block" id="contact-edit-block-link" ><img src="images/b_block.gif" alt="Block contact" title="Block contact"/></a> <a href="contacts/$contact_id/block" id="contact-edit-block-link" ><img src="images/b_block.gif" alt="Block/Unblock contact" title="$block_text"/></a>
<a href="contacts/$id/drop" id="contact-edit-drop-link"><img src="images/b_drop.gif" alt="Delete contact" title="Delete contact"/></a> <a href="contacts/$contact_id/drop" id="contact-edit-drop-link"><img src="images/b_drop.gif" alt="Delete contact" title="Delete contact"/></a>
</div> </div>
<div id="contact-edit-nav-end"></div> <div id="contact-edit-nav-end"></div>
</div> </div>
<div class="contact-dit-end" ></div> <div id="contact-edit-end" ></div>
$profile_select
$blocked
<form action="contacts/$contact_id" method="post" >
<input type="hidden" name="contact_id" value="$contact_id">
<div class="contact-edit-profile-select-text">
<h4>Profile Visibility</h4>
<p>Please choose the profile you would like to display to $name - when he/she connects securely to your profile page.
</p>
</div>
$profile_select
<div id="contact-edit-profile-select-end"></div>
<input class="contact-edit-submit" type="submit" name="submit" value="Submit" />
<div id="contact-edit-rating-wrapper">
<h4>Online Reputation</h4>
<p>
Occasionally your friends may wish to inquire about this person's online legitimacy. You may help them choose whether or not to interact with this person by providing a 'reputation' to guide them.
</p>
<div id="contact-edit-rating-select-wrapper">
$rating
</div>
<div id="contact-edit-rating-explain">
<p>
Please take a moment to elaborate on this selection if you feel it could be helpful to others.
</p>
<textarea id="contact-edit-rating-text" name="reason" rows="3" cols="64" >$reason</textarea>
</div>
</div>
$groups $groups
$rating <input class="contact-edit-submit" type="submit" name="submit" value="Submit" />
$reason
</form> </form>
</div> </div>

View file

@ -4,18 +4,43 @@
function contact_profile_assign($current) { function contact_profile_assign($current) {
$o = ''; $o = '';
$o .= "<select id=\"contact_profile_selector\" name=\"profile_assign\" />"; $o .= "<select id=\"contact-profile-selector\" name=\"profile-assign\" />\r\n";
$r = q("SELECT `profile-name` FROM `profile` WHERE `uid` = %d", $r = q("SELECT `id`, `profile-name` FROM `profile` WHERE `uid` = %d",
intval($_SESSION['uid'])); intval($_SESSION['uid']));
if(count($r)) { if(count($r)) {
foreach($r as $rr) { foreach($r as $rr) {
$selected = (($rr['profile-name'] == $current) ? " selected=\"selected\" " : ""); $selected = (($rr['id'] == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"{$rr['profile-name']}\" $selected >{$rr['profile-name']}</option>"; $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
} }
} }
$o .= "</select>"; $o .= "</select>\r\n";
return $o; return $o;
} }
function contact_reputation($current) {
$o = '';
$o .= "<select id=\"contact-reputation-selector\" name=\"reputation\" />\r\n";
$rep = array(
0 => "Unknown | Not categorised",
1 => "Block immediately",
2 => "Shady, spammer, self-marketer",
3 => "Known to me, but no opinion",
4 => "OK, probably harmless",
5 => "Reputable, has my trust"
);
foreach($rep as $k => $v) {
$selected = (($k == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
}
$o .= "</select>\r\n";
return $o;
}

View file

@ -7,7 +7,7 @@
</div> </div>
<div class="contact-entry-photo-end" ></div> <div class="contact-entry-photo-end" ></div>
</div> </div>
<div class="contact-entry-nav-wrapper" <div class="contact-entry-nav-wrapper" >
<div class="contact-entry-name" id="contact-entry-name-$id" >$name</div> <div class="contact-entry-name" id="contact-entry-name-$id" >$name</div>
<div class="contact-entry-break"></div> <div class="contact-entry-break"></div>

View file

@ -369,6 +369,7 @@ input#dfrn-url {
.contact-entry-direction-icon { .contact-entry-direction-icon {
margin-top: 24px; margin-top: 24px;
float: left; float: left;
margin-right: 2px;
} }
.contact-entry-photo img { .contact-entry-photo img {
border: none; border: none;
@ -650,4 +651,74 @@ input#dfrn-url {
margin-right: 20px; margin-right: 20px;
padding: 10px; padding: 10px;
border: 1px solid #CCCCCC; border: 1px solid #CCCCCC;
} }
#contact-edit-wrapper {
margin-top: 50px;
}
#contact-edit-banner-name {
font-size: 1.4em;
font-weight: bold;
margin-left: 30px;
}
#contact-edit-links img {
margin-left: 20px;
border: none;
}
#contact-edit-direction-icon {
float: left;
margin-top: 70px;
margin-right: 2px;
}
#contact-edit-photo {
float: left;
}
#contact-edit-photo-end {
clear: both;
}
#contact-edit-photo-wrapper {
float: left;
}
#contact-edit-nav-wrapper {
float: left;
}
#contact-edit-end {
clear: both;
}
#contact-profile-selector {
width: 175px;
margin-left: 175px;
}
#contact-reputation-selector {
margin-left: 175px;
}
#contact-edit-rating-text {
margin-left: 175px;
}
.contact-edit-submit {
margin-top: 20px;
margin-left: 50px;
}
#block-message {
margin-top: 20px;
width: 180px;
color: #FF0000;
font-size: 1.1em;
border: 1px solid #FF8888;
background-color: #FFEEEE;
padding: 10px;
}

View file

@ -8,13 +8,7 @@ profile photo to self contact page? - resolve profile photo inconsistency
contact editor contact editor
profile selector
block
block photo block photo
remove
reputation
profile "you name it" field profile "you name it" field