Jump to content
DevFuse Forums

[RESOLVED] Allow certain group to also set start/close times


ismadman

Recommended Posts

I am trying to allow a group to be able to set start/close time in Create New Topic

At the moment only super moderators ( root, mod etc ) are the only ones allowed

I know where to edit it

( sources/classes/post/class_post.php )

The code I need is something to wrap around this

		$this->can_set_open_time  = ( $this->ipsclass->member['g_is_supmod'] ) ? $this->ipsclass->member['g_is_supmod'] : ( isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_open_time']) ? intval( $this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_open_time'] ) : 0 );
	$this->can_set_close_time = ( $this->ipsclass->member['g_is_supmod'] ) ? $this->ipsclass->member['g_is_supmod'] : ( isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_close_time']) ? intval( $this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_close_time'] ) : 0 );

 

Or to add an

<if=
..........
/if>

Around this

 

		$this->can_set_open_time  = 1;
	$this->can_set_close_time = 1;

Underneath it , pertaining to the group I want to allow to see it . And use it .

My group id is 7 .

So Supermods and group 7 can use the Setting opening and closing time section only

screenmod.jpg

Any ideas anyone . Sorry if i'm not making sense . More info just ask me :D

Link to comment
Share on other sites

  • Management

Open the class_post.php file

 

Find:

		$this->can_set_open_time  = ( $this->ipsclass->member['g_is_supmod'] ) ? $this->ipsclass->member['g_is_supmod'] : ( isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_open_time']) ? intval( $this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_open_time'] ) : 0 );
	$this->can_set_close_time = ( $this->ipsclass->member['g_is_supmod'] ) ? $this->ipsclass->member['g_is_supmod'] : ( isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_close_time']) ? intval( $this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_close_time'] ) : 0 );

 

Replace With:

		if($this->ipsclass->member['g_is_supmod'] OR isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_open_time']) OR $this->ipsclass->member['mgroup'] == '7')
	{
		$this->can_set_open_time = 1;	
	}
	if($this->ipsclass->member['g_is_supmod'] OR isset($this->ipsclass->member['_moderator'][ $this->forum['id'] ]['mod_can_set_close_time']) OR $this->ipsclass->member['mgroup'] == '7')
	{
		$this->can_set_close_time = 1;	
	}

 

You could also add the group 7 as moderator of the forum and only grant them open and close time rights.

Link to comment
Share on other sites

Ok :D

 

Now how would I include something like this to show the time remaining in the section ???

 

<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown(2010,1,1,0,0);

// Date range is from 
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
 // make a unix timestamp for the given date
 $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

 // get current unix timestamp
 $today = time();

 $difference = $the_countdown_date - $today;
 if ($difference < 0) $difference = 0;

 $days_left = floor($difference/60/60/24);
 $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
 $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

 // OUTPUT
 echo "Today's date ".date("F j, Y, g:i a")."<br/>";
 echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
 echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>

 

As I want to show how much time is left ???

Link to comment
Share on other sites

  • Management
Ok :D

 

Now how would I include something like this to show the time remaining in the section ???

 

<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown(2010,1,1,0,0);

// Date range is from 
// the year 1970 to 2038
//--------------------------
function countdown($year, $month, $day, $hour, $minute)
{
 // make a unix timestamp for the given date
 $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

 // get current unix timestamp
 $today = time();

 $difference = $the_countdown_date - $today;
 if ($difference < 0) $difference = 0;

 $days_left = floor($difference/60/60/24);
 $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
 $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

 // OUTPUT
 echo "Today's date ".date("F j, Y, g:i a")."<br/>";
 echo "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
 echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>

 

As I want to show how much time is left ???

 

How much time left before topic is closing? Where did you want to display it on the topic?

Link to comment
Share on other sites

  • Management

Open sources/lib/func_topic_threaded.php

 

Find:

 

		//-----------------------------------------
	// Render the original post
	//-----------------------------------------

 

Add Above:

 

		//-----------------------------------------
	// Michael Edit (START)
	//-----------------------------------------

	if($this->topic['topic_close_time'] > time())
	{
		$date_arr = $this->ipsclass->unixstamp_to_human($this->topic['topic_close_time']);
		  $the_countdown_date = mktime($date_arr['hour'], $date_arr['minute'], 0, $date_arr['month'], $date_arr['day'], $date_arr['year'], -1);

		  $today = time();

		  $difference = $the_countdown_date - $today;
		  if ($difference < 0) $difference = 0;

		  $days_left = floor($difference/60/60/24);
		  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
		  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

		  $this->topic['human_topic_close_time'] = "( Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left )";
	}

	//-----------------------------------------
	// Michael Edit (END)
	//-----------------------------------------

 

Save sources/lib/func_topic_threaded.php

 

Open sources/lib/func_topic_linear.php

 

Find:

 

		if ( $this->lib->topic_view_mode == 'linearplus' and $this->topic['posts'] > 0 )
	{
		$this->output .= $this->ipsclass->compiled_templates['skin_topic']->topic_page_top( array( 'TOPIC' => $this->topic, 'FORUM' => $this->forum ), 1 );
	}

 

Add Above:

 

		//-----------------------------------------
	// Michael Edit (START)
	//-----------------------------------------

	if($this->topic['topic_close_time'] > time())
	{
		$date_arr = $this->ipsclass->unixstamp_to_human($this->topic['topic_close_time']);
		  $the_countdown_date = mktime($date_arr['hour'], $date_arr['minute'], 0, $date_arr['month'], $date_arr['day'], $date_arr['year'], -1);

		  $today = time();

		  $difference = $the_countdown_date - $today;
		  if ($difference < 0) $difference = 0;

		  $days_left = floor($difference/60/60/24);
		  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
		  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

		  $this->topic['human_topic_close_time'] = "( Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left )";
	}

	//-----------------------------------------
	// Michael Edit (END)
	//-----------------------------------------

 

Save sources/lib/func_topic_linear.php

 

Open your admin cp > look & feel tab > edit template html > Topic View > topic_page_top

 

And place {$data['TOPIC']['human_topic_close_time']} where you want to display the countdown.

Link to comment
Share on other sites

Great !

That all works ....except one problem :(

if I set the finish date to say 22.15

And it is 22.00 it comes back with

"Countdown 0 days 10 hours 15 minutes left"

Where as there is only 15 minutes left

and after those fifteen minutes it closes the topic yet

it said 10 hours left ??

Think I need a radio button in the start / close fields for AM/PM

It is too confusing for the average user anyway to have to put in 19.26 lol instead of 7.26 pm

Everything works except that little glitch

Link to comment
Share on other sites

Yep that worked perfectly thanks2.gif

Now to :huh: My next question :lol:

How would I get rid of 0 days 0 hours etc and just show the time remaining

eg: 0 days 0 hours 58 minutes left

should read

eg: 58 minutes left ?

Link to comment
Share on other sites

  • Management
Yep that worked perfectly thanks2.gif

Now to :huh: My next question :lol:

How would I get rid of 0 days 0 hours etc and just show the time remaining

eg: 0 days 0 hours 58 minutes left

should read

eg: 58 minutes left ?

 

If I'm reading you right, try something like this.

 

			  $days_left = floor($difference/60/60/24);
		  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
		  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

if($days_left != '0')
{
$days_text = $days_left." days";
}

if($hours_left != '0')
{
$hours_text = $hours_left." hours";
}


		  $this->topic['human_topic_close_time'] = "( Countdown ".$days_text." ".$hours_text." ".$minutes_left." minutes left )";

Link to comment
Share on other sites

Yep that worked *ismadman needs more tutoring as he can't work out why that worked lol*

So in the topic start and topic close section

is there anyway I can change the time from 24 hour to 12 and add an am pm button ?

( this would work well as a mod btw )

Link to comment
Share on other sites

  • Management
Yep that worked *ismadman needs more tutoring as he can't work out why that worked lol*

So in the topic start and topic close section

is there anyway I can change the time from 24 hour to 12 and add an am pm button ?

( this would work well as a mod btw )

 

Haven't checked through the code, but shouldn't be too hard, I'm still quite busy for the next few weeks, so won't be able to take a look at it just yet, can point you where to edit it though.

Link to comment
Share on other sites

Haven't checked through the code, but shouldn't be too hard, I'm still quite busy for the next few weeks, so won't be able to take a look at it just yet, can point you where to edit it though.

YES PLEASE

*always willing to learn*

Link to comment
Share on other sites

  • Management
YES PLEASE

*always willing to learn*

 

In the sources/classes/post/class_post.php file, look for the function convert_open_close_times() function, that is where the text input fields are converted into a unix time and saved into the database.

 

In function mod_options, the below code is for turning the unix time saved in the database back to the text input format of dd/mm/yy for when editing a topic with a previous close/open time filled in.

 

			$mytimes['open_time']  = isset($_POST['open_time_time'])  ? $_POST['open_time_time']  : '';
		$mytimes['open_date']  = isset($_POST['open_time_date'])  ? $_POST['open_time_date']  : '';
		$mytimes['close_time'] = isset($_POST['close_time_time']) ? $_POST['close_time_time'] : '';
		$mytimes['close_date'] = isset($_POST['close_time_date']) ? $_POST['close_time_date'] : '';

		if ( !isset($open_date) OR !$open_date )
		{
			if ( isset($this->topic['topic_open_time']) AND $this->topic['topic_open_time'] )
			{
				$date				 = $this->ipsclass->unixstamp_to_human($this->topic['topic_open_time']);
				$mytimes['open_date'] = sprintf("%02d/%02d/%04d", $date['month'], $date['day'], $date['year'] );
				$mytimes['open_time'] = sprintf("%02d:%02d"	 , $date['hour'] , $date['minute'] );
			}
		}

		if ( !isset($close_date) OR !$close_date )
		{
			if ( isset($this->topic['topic_close_time']) AND $this->topic['topic_close_time'] )
			{
				$date				  = $this->ipsclass->unixstamp_to_human($this->topic['topic_close_time']);
				$mytimes['close_date'] = sprintf("%02d/%02d/%04d", $date['month'], $date['day'], $date['year'] );
				$mytimes['close_time'] = sprintf("%02d:%02d"	 , $date['hour'] , $date['minute'] );
			}
		}

 

And of course the template bit Post Screen > mod_options is for displaying in on the users screen.

Link to comment
Share on other sites

ummm....:huh:

Ok ..... i'll give it a go :lol:

BTW is there anyway of stopping the poster of the topic from editing the start/finish time ?

As I just tested it with a user and the user can change everything :(

Link to comment
Share on other sites

  • Management
ummm.... :huh:

Ok ..... i'll give it a go :lol:

BTW is there anyway of stopping the poster of the topic from editing the start/finish time ?

As I just tested it with a user and the user can change everything :(

 

Is that user in member group 7?

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

Guest
This topic is now closed to further replies.
×
×
  • Create New...